开发者

Why doesn't Perl's strictures complain about an undeclared $a?

开发者 https://www.devze.com 2022-12-22 17:03 出处:网络
Why is 开发者_如何学Cthere no error issued by strict: use strict; $a = $a + 1; $a and $b are special globals used by sort, so they\'re always defined.Try it with $c instead and you will get an error

Why is 开发者_如何学Cthere no error issued by strict:

use strict;

$a = $a + 1;


$a and $b are special globals used by sort, so they're always defined. Try it with $c instead and you will get an error.


Although strict does not complain about the special $a and $b variables, perlcritic will detect their usage:

Magic variables should be assigned as "local"... (Severity: 4)


$a is a special global variable. It doesn't need to be declared. See perldoc perlvar.


In Perl there are some global variables. Here $a and $b are used in the sort function.

I think you might have noticed, like in this statement:

sort { $a <=> $b } @array_name ; 
0

精彩评论

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