The difference you're seeing is due to the complexity (or lack thereof) of the expression in the @{}.

Simple bits of code that can't possibly have local state to unwind or exception handling to perform will work in your test case. That's why the modulo test is OK. (Mind you, its working is an undocumented and unreliable accident, but this being the Monastery I'm not stopping with RTFM.)

More complex bits of code that may have local state to be unwound trigger Perl to make copies of their results when they exit. Classic examples of such expressions are user subroutines and the do BLOCK construct, but they can also arise in other circumstances. Since pattern matches can do really weird and complex things, putting a regex in your array reference expression forces the final result of the expression to be copied ... and that's what leads to the "bizarre copy" message.

The fact that Perl makes this distinction is the basis of an important optimization: Introducing what looks like a code block doesn't necessarily impose the overhead of a code block. The overhead is imposed only if something that looks dangerous or complex appears inside the given block.

For further info on this phenomenon, grep the Perl source code for the constant HINT_BLOCK_SCOPE.

PS: The fact that do BLOCK forces copies is exactly the reason why do { local *FH } makes an anonymous glob value every time it's evaluated.

    -- Chip Salzenberg, Free-Floating Agent of Chaos


In reply to All code blocks are not created equal: HINT_BLOCK_SCOPE by chip
in thread Potential Ternary Operator Bug by davorg

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.