in reply to Re^2: 'open for read' fails as "no such file or directory" but file is there
in thread 'open for read' fails as "no such file or directory" but file is there
Here's a suggestion for future development -- instead of creating the filename to be opened just in the open statement, create it ahead of time:
You may hear about using autodie instead, but I like writing out the open statement and the die statement, as it gives the debugger me more information from the developer me. In this case, if it fails, you can immediately copy and paste the filename into an ls command and check to see if Perl can't find the file .. or if developer me is an idiot. :)my $filename = # complicated work that builds filename open ( my $fh, '<', $filename ) or die "Unable to open $filename for read: $!"; # ... close ( $fh );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: 'open for read' fails as "no such file or directory" but file is there
by kcott (Archbishop) on Nov 02, 2016 at 20:40 UTC | |
by talexb (Chancellor) on Nov 02, 2016 at 21:09 UTC |