develooper Front page | perl.perl5.porters | Postings from February 2013

Re: Salvaging lexical $_ from deprecation

Thread Previous | Thread Next
Rafael Garcia-Suarez
February 19, 2013 21:27
Re: Salvaging lexical $_ from deprecation
Message ID:
On 19 February 2013 22:14, Jesse Luehrs <> wrote:
> On the contrary, $_ is basically useless except for the global form. Or
> are you saying that there shouldn't be any way to implement things like
> Try::Tiny (which does something along the lines of
> "sub catch (&) { local $_ = $@; $_[0]->() }") without using XS? The only
> serious use of $_ I have ever seen (or used personally) is when $_ is
> implicitly localized by some other code (whether that code is perl
> itself in a for loop, or in some other module). This cannot work when $_
> is lexical, and making $_ lexical in fact breaks any code like that.
> "my $_ = 'foo'; my @bar = any { $_ eq 'a' } qw(a b c)" for instance.
> That is why it has been deprecated.

You're pointing at an incomplete implementation to dismiss the whole
feature. This short-sighted criticism might be valid for bug fixes, not
for new language features.

> Also on the contrary, both @_ and $1 are localized, not lexicalized.

I agree for @_. I also agree that @_ is a kludge, please see the number
of bugs reported over the years about the stack not being refcounted;
so do not take a kludge as an example.
But the $<digit> variables are implicitly lexically scoped for a definition
of scope that includes a last sight of a pattern match. In other contexts
their behaviour is not guaranteed.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About