develooper Front page | perl.perl5.porters | Postings from March 2008

Re: local $@ has an unwanted side effect

Thread Previous | Thread Next
From:
David Nicol
Date:
March 21, 2008 09:56
Subject:
Re: local $@ has an unwanted side effect
Message ID:
934f64a20803210956nf731471u3cf722f7affaa9d1@mail.gmail.com
$ perl -le 'sub localdie { local $@; die "DIED\n" }; eval {
localdie(); }; print $@||"cleared\n"'
cleared

>  Why? The docs doesn't say this. The fact that die actually sets $@
>  and not the outer eval { } that does the assignment is not mentioned
>  or even hinted at in the docs, and there is little benefit from this
>  behavior.

i don't think it is accurate to say "die sets $@"
I believe eval sets $@ to whatever the "death rattle" of the contents
were, and die
is a way of forcing such.

I believe local sets aside the current value of something until its
scope is torn down,
then it assigns it back.

I believe the confusion arises from lack of explicit documentation of
the order of
the two operations in question here, which are, in the order they appear to be
happening, 1: assignment of "DIED\n" to $@  2: restoring the old value

I think it is reasonable to expect the assignment of the death rattle to $@ by
the eval framework would occur _after_ the stack frame is torn down including
the restoration of local variables.

I think Abigail can be something of a show-off.

-- 
... but world war IV will be fought with rocks

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About