Apart from the links already provided,
my/local, space/time might be helpful;
our is different to both. Apart from
our, you have also
use vars LIST. They are similar, but different. Both create package globals, but variables created with
our are also
file lexical scoped. If you have multiple packages (namespaces) in one file, a variable declared with
our is visible in all those packages but file scoped for alien packages, because a symbol table slot only exists for the package the variable was declared in:
use strict;
package foo;
our $quux = "Howdy, world!\n";
# dump symbol table
print "foo: $_ => $foo::{$_}\n" for keys %foo::;
package bar;
# dump symbol table
print "bar: $_ => $bar::{$_}\n" for keys %bar::;
print $quux;
__END__
foo: quux => *foo::quux
Howdy, world!
There you have the "does not necessarily create a variable" part - no variable is created in package bar. The variable $quux is shared between both packages - they would say "it's our $quux" if they could speak. Same applies for variables declared with our in different files. Having a file as
# file include.pl
use strict;
our $me;
sub japh {
print $me,"\n";
}
to be included in a main script
#!/usr/bin/perl
use strict;
our $me = "Just another perl hacker";
require "include.pl";
japh();
running the main script will output
Just another perl hacker
The $me variable is shared between the two files. That's what our means ;-)
--shmem
update: corrected "file scoped" to "lexical scoped". See Re^4: Mine or Ours.
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
-
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.