Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by ikegami (Patriarch)
on Oct 09, 2011 at 05:18 UTC ( [id://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.

Replies are listed 'Best First'.
Re^7: Short-circuiting a map list. (This works! But ...)
by BrowserUk (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://930419]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-23 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found