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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|