Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.

Cheers,
Erik


Comment on Re: Re: Help needed understanding global variables in Perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (17)
As of 2015-07-30 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls