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

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
Node Status?
node history
Node Type: perlquestion [id://38321]
Approved by root
[Eily]: Clearly this needs some advanced JDWIMA (Just Do What I Mean Already!) magic
[Eily]: I hear perl 8 will even DWYM even when you're not really sure what you mean either

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-09-20 15:03 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (237 votes). Check out past polls.