(those declared with our or with a fully qualified name)

According to the docs, variable symbols declared with our are lexical symbols (although the symbol table entry they refer to is a package global):

our associates a simple name with a package variable in the current package for use within the current scope. When use strict 'vars' is in effect, our lets you use declared global variables without qualifying them with package names, within the lexical scope of the our declaration. In this way our differs from use vars , which is package scoped.

What makes them look like non-lexicals is their auto-vivification of package globals.

Consider:

# file foo our $foo = 'hello world!';
#!/usr/bin/perl use strict; $\ = "\n"; print "no \$foo" unless defined $main::{foo}; require 'foo'; # or do 'foo' my $first = <<'EOH'; print "\$foo defined" if defined $main::{foo}; EOH eval $first; my $second = <<'EOH'; print $main::foo; EOH eval $second; __END__ no $foo $foo defined hello world!

and

#!/usr/bin/perl use strict; $\ = "\n"; print "no \$foo" unless defined $main::{foo}; require 'foo'; # or do 'foo' print $main::foo;

The string evals show that our effectively allocates a symbol table entry for the package. The second example shows that after the compilation phase a symbol table entry main::foo has been allocated.

I think of our as a hybrid beast. It is global in the sense that it generates a global, and a variable declared with our is an alias to the symbol table entry. It is lecical however in that it is transparent to multiple packages in a file.

--shmem

_($_=" "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^2: overview/tutorial on packages - creation and use by shmem
in thread overview/tutorial on packages - creation and use by chexmix

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.