3 ms·
>By default syscalls that fail set $? (which can be ignored and usually is) and don't die, and making them die breaks a lot of library code that only "works" be
by draegtun 13y ago
>By default syscalls that fail set $? (which can be ignored and usually is) and don't die, and making them die breaks a lot of library code that only "works" because it ignores errors
The solution to this is to use the autodie pragma (https://metacpan.org/pod/autodie https://metacpan.org/pod/autodie) which has been part of the Perl core since 5.10.1 (released in Aug 2009):
use 5.016;
use warnings;
use autodie;
open my $fh, '<', "somefile"; # this file doesn't exist
So above will now produce a runtime error - Can't open 'somefile' for reading: 'No such file or directory' at...
And autodie is lexically scoped so it won't break any library code.