Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

use strict, strange behavior with single character variables

by johnny_carlos (Scribe)
on May 09, 2002 at 22:09 UTC ( #165537=perlquestion: print w/ replies, xml ) Need Help??
johnny_carlos has asked for the wisdom of the Perl Monks concerning the following question:

Hola Monks,
I've been pulling my hair out for quite a while(more time than I want to admit) trying to figure out why this:
use strict; $a++; print $a;
actually prints "1", when it *thought* it should give a compile-time error for not declaring $a. I felt as though I had witnessed the impossibe. For a while there I was questioning my entire existence, and my world was about to collapse since everything I've ever known to be real and true suddenly was not.

I still don't know what the problem is, but my fears were alleviated when I expanded my minimalist test case to this:
use strict; $aaa++; print $aaa;
...and this works like it should, dying a horrible, miserable death.

So whats the deal? Anyone know why single character variable names slip through the cracks under the use strict pragma?? Or am I not seeing something?

Thanks!

John

Comment on use strict, strange behavior with single character variables
Select or Download Code
Re: use strict, strange behavior with single character variables
by perlplexer (Hermit) on May 09, 2002 at 22:13 UTC
Re: use strict, strange behavior with single character variables
by grep (Monsignor) on May 09, 2002 at 22:14 UTC
    $a and $b are special. They belong to sort (well really they belong to the main package) so they are predeclared.

    grep
    Unix - where you can throw the manual on the keyboard and get a command
Re: use strict, strange behavior with single character variables
by Zaxo (Archbishop) on May 09, 2002 at 22:16 UTC

    See perlvar. $a and $b are package globals sacred to sort. They are exempt from strict, but don't use them. They will cause strange behavior if sort is called.

    After Compline,
    Zaxo

Re: use strict, strange behavior with single character variables
by Rex(Wrecks) (Curate) on May 09, 2002 at 22:19 UTC
    $a is a special var used by sort.

    From the Camel:
    "$a PKGThis var is used by the sort function to hold the first of each pair of values to be compared ($b is used to hold the second). (blah...blah...blah) Because it is a global, it is exempt from use strict ; complaints."

    It is a special var and should not really be used outside the sort function.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: use strict, strange behavior with single character variables
by Anonymous Monk on May 09, 2002 at 22:23 UTC
    Oh wow! Cool. I see the light now. Thanks everyone.
    John
delete me
by NodeReaper (Curate) on May 09, 2002 at 22:28 UTC

    Reason: (particle) delete - double-post of delete me

    For more information on this node visit: this

Re: use strict, strange behavior with single character variables
by particle (Vicar) on May 09, 2002 at 22:28 UTC
    uh...ditto to everyone above. ;)

    but seriously... this thread will now be the only place i point people with this question. i've added it to my personal nodelet, where it shall remain in perpetuity, at the ready.

    ~Particle *accelerates*

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://165537]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-07-31 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls