|
|
|
|
|
by draegtun
5256 days ago
|
|
re: open() creating temporary file if file arg is undef Fortunately both IO::File (core module) & Path::Class don't do this: use IO::File;
my $fh = IO::File->new( $config->{file_path}, 'r' )
or die "can't open $config->{file_path}: $!";
use Path::Class qw<file>;
my $fh = file( $config->{file_path} )->openr;
Both above spot the undef gotcha. NB. And ->openr() throws an exception.ref: https://metacpan.org/module/IO::File | https://metacpan.org/module/Path::Class |
|
The builtin open() even tries to spot when it's not intentional. The documentation puts "undef" in quotations in the section where it introduces the feature (suggesting it has to be the literal), and the implementation goes to some effort to agree with it. For example, the following code dies:
In the case in the article it's a bug in the implementation, combined with a typo, which introduces the little known feature.Using Path::Class obfuscates the open, to my eyes. Using IO::File is a nice suggestion. Your lock_keys suggestion below will probably be our update to the code for future protection, though.