Solved

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

Posted on 2003-10-30
6
185 Views
Last Modified: 2013-11-19
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..
0
Comment
Question by:phil34
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:BioI
ID: 9649510
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...?
0
 
LVL 2

Accepted Solution

by:
ultimatemike earned 500 total points
ID: 9649539
It doesn't catch it because $a and $b are special variables used in sort.

ie

sort { $a cmp $b} @list;



Strict doesn't complain because they are valid variables.
0
 
LVL 3

Expert Comment

by:BioI
ID: 9649545
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
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 3

Expert Comment

by:BioI
ID: 9649548
okay, too late again :-)
0
 

Author Comment

by:phil34
ID: 9650978
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.
0
 
LVL 2

Expert Comment

by:ultimatemike
ID: 9650999
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 :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question