Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-10-30
6
Medium Priority
?
189 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

715 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