Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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...

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
    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?

What's my password?
Create A New User
Domain Nodelet?
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 studying the Monastery: (3)
As of 2021-12-01 13:13 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (10 votes). Check out past polls.