Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Re: fixing use of

by clintp (Curate)
on Dec 18, 2001 at 02:25 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2021-04-15 14:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found