[oak perl] untrappable perl errors

George Woolley george at metaart.org
Wed May 28 15:21:26 CDT 2003


On Wednesday 28 May 2003 10:56 am, Belden Lyman wrote:
> This I understand:
>
>    $ perl -le 'do{return}; print "still here\n"'
>    Can't return outside a subroutine at -e line 1.
>
> But why doesn't $@ get set with above message?
>
>    $ perl -le 'eval{do{return}}; print "error: $@"'
>    error:
>
> Belden

Belden,
Interesting.
Based on your email, I've tried a number of returns in evals
that I thought wouldn't work; 
and all of them did work.

I found Programming Perl quite helpful in explaining this.
See two relevant passages from it
after my "signature".

     George

...................................
from Programming Perl (3rd Edition)
Perl Functions in Alphabetic Order
eval
..................................
... For either form of eval, the value returned from an eval is the value of 
the last expression evaluated, just as with subroutines. Similarly, you may 
use the return operator to return a value from the middle of the eval. ...

...................................
from Programming Perl (3rd Edition)
Perl Functions in Alphabetic Order
return
..................................
... This operator causes the current subroutine (or eval or doFILE) to return 
immediately with the specified value. Attempting to use return outside these 
three places raises an exception. ...



More information about the Oakland mailing list