Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^6: Short-circuiting a map list. (This works! But ...)

by ikegami (Pope)
on Oct 09, 2011 at 05:18 UTC ( #930419=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Short-circuiting a map list. (This works! But ...)
in thread Short-circuiting a map list.

It's not the last statement of the sub, but it is the last statement of the do. What do you think do returns? The value to which the loop evaluates, which isn't defined.


Comment on Re^6: Short-circuiting a map list. (This works! But ...)
Select or Download Code
Re^7: Short-circuiting a map list. (This works! But ...)
by BrowserUk (Pope) on Oct 09, 2011 at 15:11 UTC
    What do you think do returns?

    I know what the do returns:

    print do{ { print 'fred'; map $_,1 .. 10 } };; fred 1 2 3 4 5 6 7 8 9 10

    The result of the last statement inside the bare block.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      No. You've already shown it doesn't do that in practice (in Re^3: Short-circuiting a map list. (This works! But ...)), and it doesn't do that according to the documentation.

      A BLOCK by itself (labeled or not) is semantically equivalent to a loop that executes once.

      If the last statement is a loop control structure like a foreach or a while, the returned value is unspecified.

      You just got lucky here.

        Your conclusion, based on those two quotes, is a non sequitur.

        1. "semantically equivalent" is not the same as "is".
        2. As already pointed out, the bare block is not "the last statement [in the subroutine]".

        2 + 2 != 22.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930419]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-12-25 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls