orlocal $@; my $book = eval { Spreadsheet::Read->new($file); };
The second example seems like "more work" to handle the error and is a lot messier. So in this case adding the "1" is superfulous since the called sub actually returns something (or doesn't).local $@; my $book; my $ok = eval { $book = Spreadsheet::Read->new($file); 1; };
A case where I'd use 1; with an or undef thrown in:
I think ultimately, the answer is like I stated above, it depends - on what you're doing and expecting; and how you tend to check for/handle exceptions.local $@; my $ok = eval { doSomethingButDontWantReturnValButCouldDie() or undef; 1; };
I've also done this; but usually it's a game time decision for me.
local $@; my $ok = eval { doSomethingButDontWantReturnValButCouldDie(); 1; } or undef;
In reply to Re^3: Can I catch a die from someone else's module?
by perlfan
in thread Can I catch a die from someone else's module?
by bartender1382
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |