I don't think that require or eval will cut it.

What is going on is that Perl will not complain if it has already compiled the fact that you have subroutines when you hit the bareword. Since strict creates a compile time complaint, it will fail without ever paying any attention to require or eval. (Unless, of course they are in a BEGIN block.)

This actually gets at some important points. The same behaviour that you see with strict comes up again with prototypes. Here is the underlying cause.

When perl (not a typo, the language is Perl, the interpreter is perl) sees your script it fundamentally has 2 different things that it does. The first is it compiles code to an internal representation, the second is that it runs that internal representation. These take place in separate passes. However some things will cause it to switch from one to the other.

While compiling if Perl sees certain things, for instance a complete BEGIN block or use, it will switch out of compiling your script to go do something else and then return to your script when it is done that. Conversely while running if your program encounters other things, for instance require and eval, it may have to go back to compiling more code.

Now the (obvious) rule is that at no point can you take into account code that you have not (yet) compiled. By the time your main script gets around to running, most stuff has compiled, and it just works. But if the code affects compilation in some way (eg telling Perl that a sub really exists, or declaring a prototype for a subroutine) then it cannot take effect until *after* Perl has seen that text.

Does that make sense?


In reply to RE: Bare Subnames by tilly
in thread is this correct? by damian

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.