Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

29. Scoping > Package Variable Trivia

Package Variable Trivia

There are only three other things to know about package variables, and you might want to skip them on the first reading:

  1. The package with the empty name is the same as main. So $::x is the same as $main::x for any x.

  2. Some variables are always forced to be in package main. For example, if you mention %ENV, Perl assumes that you mean %main::ENV, even if the current package isn’t main. If you want %Fred::ENV, you have to say so explicitly, even if the current package is Fred. Other names that are special this way include INC, all the one-punctuation-character names like $_ and $$, @ARGV, and STDIN, STDOUT, and STDERR.

  3. Package names can contain ::, but not variable names. You can have a variable named $DBD::Oracle::x. This means the variable xin the package DBD::Oracle; it has nothing at all to do with the package DBD, which is unrelated. Isaac Newton is not related to Olivia Newton-John, and $Newton::Isaacis not related to $Newton::John::Olivia. Even though it appears that they both begin with Newton, the appearance is deceptive. $Newton::John::Oliviais in package Newton::John, not package Newton. The slogan is: “Packages do not nest.”


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint