Solved

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

Posted on 2003-10-30
6
181 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now