[Melbourne-pm] Pls explain?

Brendon Oliver brendon.oliver at gmail.com
Tue Oct 23 18:44:36 PDT 2007

On Wednesday 24 October 2007 11:33:33 Jacinta Richardson wrote:

> You can find lots more on this bug by searching for:
> 	my if 0
> Abigail from Perl Monks explains it thus:
> ====
> 	my $x if undef;
> my has compile-time *and* run-time effects. At compile time, the compiler
> knows about the variable, etc. At run-time, values are set, my $x; makes
> that $x becomes undef. So far, so good.
> However, for efficiency reasons, if Perl exits a block, it will actually
> *not* delete any variables lexical to the block. You cannot refer to them
> anymore (the compiler takes care of that), but the data structure build for
> it remains. Perl does this because it is likely that you reenter a block
> and if the structure remains, Perl can save time rebuilding it. However,
> with my $x if undef, no run-time effect on $x happens when reentering the
> block. (The first time the block is entered, the datastructure gets build
> when $x is used). And since the structure doesn't get rebuild, the value
> doesn't get reset either. So, you have created a static variable....
> ====

Thanks for the research / explanation Jacinta - much appreciated.

> It was covered in the "This Week on p5p 2000/05/21"
> (http://www.perl.com/pub/a/2000/05/p5pdigest/THISWEEK-20000521.html#my_x_if

> Apparently Perl 5.10 throws a big fat warning if it sees this kind of
> behaviour.

Gee, took only 7.5 years to fix (counting from the article publication)! Now 
*that's* progress! ;-P


- Brendon

BREAKFAST.COM Halted... Cereal Port Not Responding.

 11:41:41 up 8 days, 23:07,  3 users,  load average: 0.10, 0.18, 0.38

More information about the Melbourne-pm mailing list