in reply to Re^3: '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

G'day Alex,

Hand-crafting your own die messages can provide a lot more information than that provided by autodie. In some cases, using die instead of autodie is entirely appropriate. However,

... or die "Unable to open $filename for read: $!";

provides no more information than

$ perl -e 'use autodie; open $fh, "<", "not_a_file"' Can't open 'not_a_file' for reading: 'No such file or directory' at -e + line 1

See my reply to the OP for more on this.

— Ken

Replies are listed 'Best First'.
Re^5: 'open for read' fails as "no such file or directory" but file is there
by talexb (Chancellor) on Nov 02, 2016 at 21:09 UTC

    Absolutely right. My current preference to hand-rolled exceptions is based on my current environment, one that I'm reluctant to modify (it's git-bash running on an Azure cloud). However, I did just check, and autodie is present in this installation (5.22.0), so I will try it the next time I build a script.

    Mostly, what also contributes to me attitude about error-checking is my background as a C programmer -- my experience has taught me to be pessimistic, and check for errors just about everywhere. :)

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.