Link to home
Start Free TrialLog in
Avatar of phil34
phil34

asked on

use strict not catching variables with one character as name ie $a

example
#!/usr/bin/perl -w
use strict;
$vara = "hello world";
print $vara;

fails to compile and strict complains. As expected. However.....

#!/usr/bin/perl -w
use strict;
$a = "hello world";
print $a;

compile and stict does not moan about the missing my in front the the declaration. why???
I have seen loads of use strict tutorials but nobody has mentioned this..
Avatar of BioI
BioI
Flag of Belgium image

however...
this only works for $a en $b I noticed.  Try this for example for $c, $x or $z and you will get the usual error-message.
I suppose this exception is included in the "strict"-module...?
ASKER CERTIFIED SOLUTION
Avatar of ultimatemike
ultimatemike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I asked around here and this is the answer I get, and which is very reasonable in fact: $a and $b are special variables used in sorting. You shouldn't use $a and $b for variable names, because these variable names will always be exepted by perl
okay, too late again :-)
Avatar of phil34
phil34

ASKER

Thankyou very much, I will write my own use strict tutorial and bring this up. I think the is very important. I thought maybe stict would allow one characters because perl has many special variable with only one character ie $! $_ $' etc although I did not think about $a and $b for the sort. I bet there are alot of people using $a and $b for variable names and not even realizing that.
It even had me confused for a second.... I figured strict would catch it if they didn't appear inside a sort block, but I guess we both learned something :)