Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
more useful options
 
PerlMonks  

Re: Passing Variables

by steves (Curate)
on Oct 23, 2004 at 18:24 UTC ( [id://401901]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Passing Variables

It might help you to understand a few very basic things I always try to teach new Perl programmers:

  • With the exception of special variables defined by Perl (well, okay you can do that too ...) there really are no "global" variables in Perl as there are in many languages. The variables you're definining in your example are package variables. Those are different than global variables.
  • To access another package's package variables, you can do one of two things:
    1. You can fully qualify them with the package name, as in $packageName::variableName;
    2. The package defining the variables can export them in a way that lets them become part of the namespace of another package. That is typically done using Exporter.

The way I think of Perl's package variables is that both the defining and using packages get to decide how "global" to make them: the defining package by how it defines and exports them; the using package by how it imports them. On the importing side, the using package is really making a decision about how it wants to pollute its own package namespace.

In addition to Export, the documentation on import and use should help you to understand this better. Some people don't realize that use lets the using package decide how much it wants to take advantage of what the package being used has decided to Export by default.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://401901]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.