Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Scalar $ENV in a package

by knight (Friar)
on Oct 25, 2000 at 15:03 UTC ( [id://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...

Replies are listed 'Best First'.
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...
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..."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found