Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hey there, here's a question for the class. Why don't you get bareword warnings under "use strict" while you're in a BEGIN {} block. Here's some code:

#!/usr/bin/perl use strict; #use warnings; #require strict; sub BEGIN { #while(calldepth < 5) { } #$strict_error_here =1; }; sub foo { #while(calldepth < 5) { } } #while(calldepth < 5) { }

Some notes about the following code:
  • Uncommenting the while() inside of BEGIN throws no warning. Doing so with use warnings in effect gives a non-numeric warning, but still allows the code to loop forever.
  • Uncommenting the while in the subroutine foo() and by itself, both produce the warning under strict;
  • Placing a use strict; doesn't do anything inside of BEGIN
  • Uncommenting $strict_error_here actually causes a parse error
  • Switching the calldepth to something like calldepth++, also produces the error.

So I guess my question is, why doesn't a bareword throw an error inside of a BEGIN function (under strict)?

My second question is, is there any reason at all for perl to not warn you when comparing against a constant in a while() or unless() function, as in the functions above.

Any insight into perl's murkiness here would be great


In reply to Why no bareword warnings while inside of BEGIN by JayBonci

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2018-04-21 14:29 GMT
    Find Nodes?
      Voting Booth?