Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found