Solved

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

Posted on 2003-10-30
6
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
 shows up in Outlook, not OWA or on phone 3 81
Specific format 21 238
removing hyperlinks from end-notes in a PDF to HTML conversion 8 140
Adjust the position 3 75
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 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