Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Re: Help needed understanding global variables in Perl

by erikharrison (Deacon)
on Mar 05, 2002 at 15:10 UTC ( #149391=note: print w/replies, xml ) Need Help??

in reply to Re: Help needed understanding global variables in Perl
in thread Help needed understanding global variables in Perl

I do not claim to have plumbed the depths of our. However, this seems to be the deal: 'our' variables are package variables, just like $main::foo, except that our makes a LEXICALLY scoped declaration that the variable has been legally imported - basically, you can use it's unqualified package name under use strict.

use strict; package foo; our $y = "This is in package foo"; # $x and $y both package $foo::x = "This is in package foo"; # variables print $foo::x; { #bare block our $x; print $x; #$x = $foo::x } #end of bare block print $x #Give a warning under use strict #because the 'our' declaration #is out of scope package bar; print $foo::y; #prints $y declared with 'our' in package foo print $foo::x; #prints $x declared with package name in foo

I don't know if that helps any, (or just confused) but there it is - the weirdness (and, I think, good use) of our.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2016-10-25 22:18 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.