开发者

When is our keyword necessary at all?

开发者 https://www.devze.com 2023-03-20 01:12 出处:网络
perl -e \'use strict;use warn开发者_JAVA技巧ings;$a=2;print $a\' It seems no warning is reported when I declare a global variable without our,so when is this keyword necessary?$a and $b are special
perl -e 'use strict;use warn开发者_JAVA技巧ings;$a=2;print $a'

It seems no warning is reported when I declare a global variable without our,so when is this keyword necessary?


$a and $b are special cases - they are reserved for sort (e.g. sort { $a <=> $b }) and shouldn't be used for your own variable names - try again using something else and see what happens!


From perlvar:

   $a
   $b      Special package variables when using "sort()", see "sort" in
           perlfunc.  Because of this specialness $a and $b don't need to
           be declared (using "use vars", or "our()") even when using the
           "strict 'vars'" pragma.
0

精彩评论

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