Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: fixing use of

by clintp (Curate)
on Dec 18, 2001 at 02:25 UTC ( [id://132697]=note: print w/replies, xml ) Need Help??


in reply to Re: fixing use of
in thread Error message when using 'our'

Not to nitpick, but thought you might find this interesting:
package main; my $var=6; sub foo { our $var; $var=5; } print $var; foo(); print $main::var; print $var;
This prints "656".

What is means is, that within the subroutine foo, I can get to the package $var without having to use a full package name ($main::var). The our declaration makes it clear that within this lexical scope "$var" means the package variable, not the lexical $var that exists in the enclosing scope.

Sometimes there are uses for "our" inside of subroutines.

update: of course I meant $main::var

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://132697]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (None)
    As of 2024-04-25 00:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found