* Jonathan Rockway <[EMAIL PROTECTED]> [2008-05-03 21:15]:
> You said you're trying to emulate $@, but $@ can be changed out
> from under you rather easily, so instead of:
> 
>   eval { foo() };
>   if($@){ error }
> 
> The defensive programmer will write:
> 
>   my $result = eval { foo() };
>   if(!defined $result){ error } # use $@ for more details, if necessary.

An even more defensive programmer will write:

    my $result;
    if ( eval { $result = foo(); 1 } ) {
        # ...
    }

That’s not necessary in every case, but if foo() can legitimately
return undef, you need it. Unfortunately the expression in `eval`
is often more complex, so it can hard to make readable.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to