Strict 'vars' and strict 'subs' are compile-time directives, so they don't apply as others pointed out.

Avoiding strict refs for speed? Ack! Pttht!

A quick walk thorugh the source reveals that way down in the bowels of op.c, Perl_ck_rvconst is the function checking strict 'refs'. The section reads:

if ((PL_hints & HINT_STRICT_REFS)&&(kid->op_private & OPpCONST_BARE)){ char *badthing = Nullch; switch (o->op_type) { case OP_RV2SV: badthing = "a SCALAR"; break; case OP_RV2AV: badthing = "an ARRAY"; break; case OP_RV2HV: badthing = "a HASH"; break; } if (badthing) Perl_croak(aTHX_ "Can't use bareword (\"%s\") as %s ref while \"strict refs\" + in use", name, badthing); }
So we've got a a bitwise AND (and a pointer deref) going on to see if we've got something that might throw a stricture error. If there's no strict, we skip this next part.

Next, we've got a switch statement with three possibilities: we wanted a SCALAR, ARRAY or HASH reference. That'll compile down to something tight and small (three comparisons, a jump-table of some kind, etc...). Only if any of these match does badthing get set and the error thrown.

So at the very worst case that doesn't actually throw an error you've got:

(Your mileage will vary greatly, I'm sure.)

So if you're worried about a small number of ANDs, pointer moving and comparisons to check for strict because you're looking for speed: look elsewhere. There's nothing to optimize here.


In reply to Re: Re: is use strict a compile time directive? by clintp
in thread is use strict a compile time directive? by princepawn

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.