[Israel.pm] lexical $_

Offer Kaye oferk at oren.co.il
Mon Mar 22 09:11:49 PST 2004

Like many others (I think :)) I was quite surprised during Gaal's lecture
which he gave at YAPC::Israel::2004 regarding the problems when using $_
([1]"A $_ gotcha"). It was not that I did not know in general that $_ is
global, but I was not aware of the details.
So you can imagine I was delighted to read that in perl5.9.1, recently
released, $_ can finally be [2]declared lexical using "my":

The default variable $_ can now be lexicalized, by declaring it like any
other lexical variable, with a simple

    my $_;

The operations that default on $_ will use the lexically-scoped version of
$_ when it exists, instead of the global $_.

This solves the entire mess Gaal was talking about, which is a great relief
for me. perl 5.9.1, here I come! :).

P.S., Gaal, you should find some other problem in Perl to talk about at next
year's YAPC, maybe it will also be fixed... ;)

[1] http://www.forum2.org/gaal/perl/Pitfall/slide001.html

Offer Kaye

More information about the Perl mailing list