Lexical $_ is now experimental
Since it was introduced in Perl v5.10, it has caused much confusion with no obvious solution:
Various modules (e.g., List::Util) expect callback routines to use the global $_. use List::Util 'first'; my $_; first { $_ == 1 } @list does not work as one would expect.
A my $_ declaration earlier in the same file can cause confusing closure warnings.
The "_" subroutine prototype character allows called subroutines to access your lexical $_, so it is not really private after all.
Nevertheless, subroutines with a "(@)" prototype and methods cannot access the caller's lexical $_, unless they are written in XS.
But even XS routines cannot access a lexical $_ declared, not in the calling subroutine, but in an outer scope, iff that subroutine happened not to mention $_ or use any operators that default to $_.
It is our hope that lexical $_ can be rehabilitated, but this may cause changes in its behavior. Please use it with caution until it becomes stable.
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |