Short answer: the strict variable declaration check occurs before the import.

Long answer: the entire program compiles, then it runs. require is a runtime operation here. So is the import() call. When those happen together, as in the case of use, the implicit BEGIN block forces those operations to occur during compilation. Any code after that (in terms of line number in the file) is subject to any changes as a result of any import() operations.

Perl always performs the strict variable checking during compilation time; that's the earliest it can possibly do so. There's no (good) way Perl can know that you intend to modify the compilation environment at runtime, so it won't delay the variable checking. Nor would you want it to in general; that'd lead to unpredictable behavior.

The best solution is to put jim in its own package. You can work around the problem by wrapping that package and the import() call in BEGIN blocks.


In reply to Re: Importing variables from package within same script by chromatic
in thread Importing variables from package within same script by moensch

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.