BooYah.pm is only a package if you begin it with:
package BooYah;

Then, all vars in that package can be accessed as $BooYah::var_name.

Of course, you can have more than one package in a script :)

I think what you're asking is "what is the default package?". The answer to that is 'main' or '' by default.

The var would have to be declared globally (no my/local) and explicitly (you are using strict now, aren't you :). BUT, it's a bad idea to rely on vars in main from the package that was required. If you do though, there are two instances I can think of:

# (1) # Foo.pl - extract # implicitly %::crap = (turd => 'yellowy brown', crap => 'browny black'); # or explicitly %main::crap = (turd => 'yellowy brown', crap => 'browny black'); # BooYah.pm - extract require 'Foo.pl'; # implicitly print $::crap{turd}; # or, explicitly print $main::crap{turd}; # (2) - give Foo.pl a namespace # Foo.pl - extract package Foo; %Foo::crap = (turd => 'yellowy brown', crap => 'browny black'); # BooYah.pm - extract require 'Foo.pl'; print $Foo::crap{turd};

Although I'm a little worried about your question. Shouldn't you be requiring the module from the script and not requiring the script from the module?!?!

Do some research on namespaces, or read perlmod documentation.

cLive ;-)


In reply to Re: Variable scope in packages. by cLive ;-)
in thread Variable scope in packages. by CuriousGeorge

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.