[oak perl] untrappable perl errors

George Woolley george at metaart.org
Wed May 28 19:43:42 CDT 2003


On Wednesday 28 May 2003 2:18 pm, Belden Lyman wrote:
> 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

Belden,
Well, that seems a reasonable assumption.
But after reading the two passages I quoted,
I now believe that return is legal within an eval
without needing to be part of a subroutine.
If that is the case,
the return in the example does not cause an error
hence there is no call on die.
Is that what you've concluded too?

I'm guessing, you'll be using the eval EXPR form of eval 
in your self-modifying code
since the documentation says the eval BLOCK form of eval
is compiled only once. 
Is that so?       

Your "toyings" sound very interesting.
If there are some key insights you feel like sharing here
at some point,
that would be most kool. 

      -- George



More information about the Oakland mailing list