[oak perl] untrappable perl errors
Belden Lyman
blyman at iii.com
Wed May 28 16:18:26 CDT 2003
George Woolley wrote:
> 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".
>
>
I'm not sure those passages explain this, though, which *does* work:
$ perl -le 'eval{die "gork!\n"}; print "error: $@"'
error: gork!
that is, if one die's within an eval(), the death message will be
in $@. I assumed that 'do{return}' was calling die() and hence would
set $@, but that obviously is not the case.
This eval{do{return}} is related to my recent toyings with self-
modifying code.
Belden
More information about the Oakland
mailing list