A really enlightening article: it threw light on what was a mysterious theme for me. I'd offer a suggestion, for the 4th code snippet, which bit me when I tried out with use strict. If we run it like this:
use strict; use warnings; package Szyewicki; our ($Robert); $Robert = "the boss"; package PoolHall; our ($Robert); $Robert = "the darts expert"; package Szyewicki; print "Here at work, 'Robert' is $Robert, but over at the pool hall, ' +Robert' is $PoolHall::Robert\n";
The result, which puzzled me at first, will be:
Here at work, 'Robert' is the darts expert, but over at the pool hall, + 'Robert' is the darts expert
It took me quite a while to decypher why: the lexical scope of the 2nd our, under package PoolHall, is the file, so, when we switch to package Szyewicki, it's still in effect, making $Robert a lexical alias to package variable $Szyewicki::Robert. To work as expected and intended, the code must be:
use strict; use warnings; package Szyewicki; our ($Robert); $Robert = "the boss"; package PoolHall; our ($Robert); $Robert = "the darts expert"; package Szyewicki; our ($Robert); print "Here at work, 'Robert' is $Robert, but over at the pool hall, ' +Robert' is $PoolHall::Robert\n";
The 3rd our alias $Robert to $Szyewicki::Robert.

In reply to Re: Variable Scoping in Perl: the basics by marcelpaulo
in thread Variable Scoping in Perl: the basics by arturo

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.