Versions Compared

Key

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

...

Code Block
bgColor#ffcccc
langperl

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

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

Compliant Solution (croak())

...

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 file name and line number of the function that invoked the function that invoked croak(). This is solution 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.

...