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}

In reply to Re: Mine or Ours by shmem
in thread Mine or Ours by logie17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.