开发者

Why doesn't Perl's strict warn about an undeclared $a?

Can someone please explain to me the below code. This behavior has been like this for a while (tested on 5.8.5, 5.8.8, 5.10.1, 5.12.2) so there must be a reason behind it?

$ perl -M5.012 -E开发者_Python百科 '$aa=2'
Global symbol "$aa" requires explicit package name at -e line 1.

$ perl -M5.012 -E '$a=2'

Thanks.


This is in the strict documentation:

Because of their special use by sort(), the variables $a and $b are exempted from this check.

Always check the docs. Most of the answers are in there :)


$a (and also $b, and many others) is a global variable. It's intended to be used in the sort function, e.g. sort { $a <=> $b } @list. perldoc perlvar lists all of perl's built-in globals and their meaning.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜