Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Help needed understanding global variables in Perl

by erikharrison (Deacon)
on Mar 05, 2002 at 15:10 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found