Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Here is a list of deprecated functions, along with their recommended alternatives , if available:

Deprecated

Preferred

UNIVERSAL::can()

object can() method

UNIVERSAL::isa()

object isa() method

die()

Carp::croak()

warn()

Carp::carp()

-t

IO::Interactive

format()

Template, Perl6::Form

...

This noncompliant code example tries to open a file , and invokes the obsolete die() method if it fails.

...

The die() method is considered deprecated , as because it prints the file name and line number in which it was invoked. This might be sensitive information.

Compliant Solution (croak())

This compliant colution solution uses the croak() function instead of die().

Code Block
bgColor#ccccff
langperl
use Carp;

my $file;
open(FILE, "<", $file) or croak "error opening $file: stopped";
# work with FILE

Unlike , die(), croak() provides the filename file name and line number of the function that invoked the function that invoked croak(). This is more useful for application code that invokes library code; in this case, croak() and carp() also will reveal the file name and line number of the application code rather than the library code.

...