in reply to Re^3: When to use eval
in thread When to use eval
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: When to use eval
by stevieb (Canon) on Feb 02, 2024 at 07:32 UTC |