If there is no package, it's ::, or main::. But that's the definition of "global" in Perl - a package variable is visible everywhere, even if you have to explicitly specify the package, while a lexical is not. It's similar to C++'s namespaces - sure, you can have more than one global variable, as long as they're in different namespaces / packages, but they're still global.

The danger in do is just that Perl 5 has conventions. And those conventions are about useing modules, not evaling file contents. And because these are the conventions, that's what people are used to. When you buck those conventions, you introduce an error-prone area where nuances of the implementation (which are generously documented, but who looks at documentation? ;->) can bite you. For example, it seems common that people expect that do FILE will import lexicals (despite the docs). But I've not yet seen someone assume that from a use MODULENAME that has, as per convention, a package declaration at the top.

That's not to say "never use do FILE" - just be sure you know what you're doing when you do so. It's an uncommon idiom, and, usually, a more common idiom would not only serve the same purpose, but be more maintainable. Even though I can't think of a good reason to use do FILE over either a proper module or a config file (depending on what the use is) doesn't mean I'm discounting the possibility. ;-)


In reply to Re^3: strict/do question by Tanktalus
in thread strict/do question by dch

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.