Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
P is for Practical
 
PerlMonks  

Scalar $ENV in a package

by knight (Friar)
on Oct 25, 2000 at 15:03 UTC ( #38321=perlquestion: print w/ replies, xml ) Need Help??
knight has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone explain to me why the scalar $ENV doesn't show up in a package with its "fully-qualified" package name?
% cat xxx.pl package script; $env = 1; $ENV = 2; print "\$env = '$env'\n"; print "\$ENV = '$ENV'\n"; print "\$script::env = '$script::env'\n"; print "\$script::ENV = '$script::ENV'\n"; % perl xxx.pl $env = '1' $ENV = '2' $script::env = '1' $script::ENV = '' %
I suppose this has something to do with the special status of %ENV, but that sure seems to run counter to the usual distinction between a same-named scalar and hash.

This behavior is consistent on Perl 5.00345 and 5.6.0, so it's not a version-specific bug, at least...

Comment on Scalar $ENV in a package
Download Code
Re: Scalar $ENV in a package
by knight (Friar) on Oct 25, 2000 at 15:10 UTC
    Apologies for the misleading node-link in the posting; I didn't read my preview closely enough. That should have read, "This behavior is consistent on Perl 5.00[345] and 5.6.0..."
Re: Scalar $ENV in a package
by cianoz (Friar) on Oct 25, 2000 at 15:19 UTC
    from "man perlvar"
           All Perl variables that begin with digits, control
           characters, or punctuation characters are exempt from the
           effects of the package declaration and are always forced
           to be in package main.  A few other names are also exempt:
    
                   ENV             STDIN
                   INC             STDOUT
                   ARGV            STDERR
                   ARGVOUT
                   SIG
    
    so adding
    print "\$main::ENV = '$main::ENV'\n";
    you get
    $main::ENV = '2'
    as expected...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-04-20 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls