Starting in Perl 5.10, it is now possible to lexically scope the context variable $_
, either explicitly as my $_;
or in a given / when
construct.
Has anyone found good uses of the lexical $_
? Does it make any constructs simpler / safer / faster?
What about situations that it makes more complicated? Has the lexical $_
introduced any bugs into your code? (since control structures that write to $_
will use the lexical version if it is in scope, this can change the behavior of the code if it contains any subroutine calls (due to loss of dynamic scope))
In the end, I'd like to construct a list that clarifies when to use $_
as a lexical, as a global, or when it doesn't matter at all.
NB: as of perl5-5.24
these experimental features are no longer part of perl.
$_
, but not all of them. That's what I would like to cover here. – Meill