Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by BrowserUk (Pope)
on Oct 09, 2011 at 15:11 UTC ( #930477=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^7: Short-circuiting a map list. (This works! But ...)
Download Code
Re^8: Short-circuiting a map list. (This works! But ...)
by ikegami (Pope) on Oct 09, 2011 at 19:18 UTC

    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.

        You can argue all you want, but it's not going to change the fact that the return value of loops (including the bare loop) is not defined. They can and do produce junk in some circumstances. There was talk of making loops act like map wrt to their return value, but it hasn't been done.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-09-20 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls