- 求职 : 软件工程师
- 论坛徽章:
- 3
|
本帖最后由 104359176 于 2014-04-13 10:06 编辑
http://perldoc.perl.org/perl5180 ... is-now-experimental
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. |
|