No.

The following works:

my $DEBUG; BEGIN { $DEBUG = $ARGV[0]; } use if $DEBUG, 'strict'; # <-- The compiler is here because # Perl executes use statements # as soon as it compiles them. # "strict" will work until the # end of this block (namely # until the end of the file). print($test); # strict error if $DEBUG

The following works:

my $DEBUG; BEGIN { $DEBUG = $ARGV[0]; if ($DEBUG) { require strict; import strict; } } # <-- The compiler is here because # Perl executes BEGIN blocks # as soon as it compiles them. # "strict" will work until the # end of this block (namely # until the end of the file). print($test); # strict error if $DEBUG

The point, however, is that the following doesn't work:

my $DEBUG; BEGIN { $DEBUG = $ARGV[0]; if ($DEBUG) { eval <<'__EOI__'; use strict; # <-- The compiler instance used # by eval is here because # Perl executes use statements # as soon as it compiles them. # "strict" will work until the # end of this block (namely # until the end of the code # passed to eval). __EOI__ } } print($test); # No strict error

Actually, I thought the second one wouldn't work either, but it does for the reason I gave in the comments.


In reply to Re^3: Controlling "use" statements by ikegami
in thread Controlling "use" statements by nodice

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.