Actually, autodie is way better than or die $!. It would rather be like this:
open my $fh, '<', $filename or die qq(Can't open $filename for $mode: '$!')It takes care to inform about the filename (in quotes, so that it stands out against the constant text), the open mode, and also wraps $! in quotes. That is exactly why I often use autodie, especially in short and quick programs when I don't want to spend time on crafting error messages.
Which error message would you prefer:
Permission denied at demo1.pl line 2. Can't open 'filename.txt' for reading: 'Permission denied' at demo2.pl line 2
In reply to Re^4: When to use eval
by haj
in thread When to use eval
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |