
...
Code Block | ||||
---|---|---|---|---|
| ||||
my $source;
open(SOURCE, "<", $source);
@lines = (<SOURCE>);
close(SOURCE);
|
It makes sure the variable containing the file name is properly defined, but it does nothing else to catch errors. Consequently, any error, such as the file not existing, being unreadable, or containing too much data to read into memory, will cause the program to abort.
...
Code Block | ||||
---|---|---|---|---|
| ||||
my $source;
open(SOURCE, "<", $source) or croak "error opening $source: $!";
@lines = (<SOURCE>);
close(SOURCE) or croak "error closing $source: $!";
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
use autodie;
my $source;
open(SOURCE, "<", $source);
@lines = (<SOURCE>);
close(SOURCE);
|
EXP32:EX2: Functions that send data to standard output or standard error need not have their return values checked. This includes print
and printf
, but only if their filehandle argument is not supplied , or is explicitly set to *STDOUT
or *STDERR
. If they send their output to any other filehandle, their return value must be checked.
EXP32:EX3: When inside error-handling code, function calls that are used to release resources, such as close()
, need not have their return values checked. Any code that falls under this exception should be explicitly documented as such.
...