So what does eval actually do, and actually trap?
Considering this code:
eval { $content = $self->web_fetch( { raw => 1 } ); }; # a $content = eval { $self->web_fetch( { raw => 1 } ); }; # b if ($EVAL_ERROR) { # $@ return $self->do_harvest_return(undef); }
(We can assume that web_fetch and do_harvest_return are methods written by us, and contain some carp and croak statements)
#1 There's an implicit statement that eval does not return true or false on it's own... the implication is that it doesn't return anything (unlike, for example, print - which returns true on a successfull print)
I assume $EVAL_ERROR will contain the first croak (or other fatal) error from the web_fetch method in both a and b
.... but what about the difference between a and b - doesn't a also report if the assignment to $content fails? - if so, why does best practice suggest b? (2nd Edition, P 277)
#2 Is there a preferred style for using eval?
In reply to What does eval actually do? by kiz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |