Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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


    --jaybonci

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

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (10)
    As of 2014-07-22 11:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (110 votes), past polls