Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Why is there no error issued by strict:

use strict;

$a = $a + 1;
like image 326
planetp Avatar asked Mar 10 '10 10:03

planetp


3 Answers

$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.

like image 141
Dave Sherohman Avatar answered Sep 20 '22 02:09

Dave Sherohman


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)

like image 40
toolic Avatar answered Sep 20 '22 02:09

toolic


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

like image 45
Eugene Yarmash Avatar answered Sep 23 '22 02:09

Eugene Yarmash