[sf-perl] Scope of a variable

Michael Friedman friedman at highwire.stanford.edu
Thu Mar 8 12:03:41 PST 2007

 From 'perldoc -f our':
              An "our" declares the listed variables to be valid
              globals within the enclosing block, file, or "eval".
              That is, it has the same scoping rules as a "my"
              declaration, but does not create a local variable.

That means that an 'our' variable is only valid within a particular  
file. Are you perhaps trying to access it from a separate file,  
either a used module or a required script?

-- Mike

On Mar 8, 2007, at 11:50 AM, nheller at silcon.com wrote:

> I'm trying to create a variable that is visible in multiple  
> namespaces.
> I tried declaring the variable using "our".
> With use strict in effect, the code seems to treat the variable as  
> a local
> in each place that it's used.  IOW, it doesn't hold value from one
> namespace to the next.
> Can anybody tell me where I'm going wrong?

Michael Friedman                     HighWire Press
Phone: 650-725-1974                  Stanford University
FAX:   270-721-8034                  <friedman at highwire.stanford.edu>

More information about the SanFrancisco-pm mailing list