Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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 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 $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
    so adding
    print "\$main::ENV = '$main::ENV'\n";
    you get
    $main::ENV = '2'
    as expected...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2014-11-26 18:51 GMT
Find Nodes?
    Voting Booth?

    My preferred Perl binaries come from:

    Results (172 votes), past polls