On 3/7/06, Jay Savage <[EMAIL PROTECTED]> wrote:
snip
> Since eval traps die, 'eval{ eval {} or die [EMAIL PROTECTED];};' is a 
> convenient
> method for propagating $@ out of deeply nested evals. It's just a way
> to save writing lots of if blocks that do nothing but pass $@ along.
snip

You had better be careful with the 'or' there.  The return value of an
eval is that of the last statement executed.  This means that

eval { $a = 0 } or die $@ ;

will fail even though the block did not have an error.  The safe way
to handle blocks is to check the value of $@ and die if it is set:

eval { $a = 0 };
die $@ if defined $@;

Although I believe you can always get away with shortening it to

eval { $a = 0 };
die $@ if $@;

since die() always (I think) adds on "at X line Y.".

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to