我们的关键字什么时候需要?

new*_*erl 5 variables perl built-in

perl -e 'use strict;use warnings;$a=2;print $a'
Run Code Online (Sandbox Code Playgroud)

当我声明没有全局变量时似乎没有报告警告our,那么这个关键字何时必要?

plu*_*lus 16

$a并且$b是特殊情况 - 它们是为sort(例如sort { $a <=> $b })保留的,不应该用于您自己的变量名称 - 再次尝试使用其他东西,看看会发生什么!


Eug*_*ash 11

来自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.
Run Code Online (Sandbox Code Playgroud)