Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: map and return

by ELISHEVA (Prior)
on Sep 03, 2009 at 12:08 UTC ( [id://793161]=note: print w/replies, xml ) Need Help??


in reply to Re^3: map and return
in thread map and return

As near as I can tell, no built-in function listed in index-functions has a prototype (just checked) and some of these behave more normally with regards to return. For instance, both map and sort are on that list. Neither map nor sort have defined prototypes, but sort treats the return inside the block as if it were returning from a subroutine, just like my custom sub foo above.

# no compile problems here! my @x = sort { return $a <=> $b; } (3, 2, 1); print "sorted: (@x)\n"; #prints: sorted (1, 2, 3)

Best, beth

Update: Struck out incorrect portion of post - forgot to include "CORE::" in the function name, as pointed out by Anonymous Monk below.

Replies are listed 'Best First'.
Re^5: map and return
by Anonymous Monk on Sep 03, 2009 at 12:27 UTC
    ..has a prototype (just checked)

    perl -le"printf qq~%10s %s \n~, $_, prototype(qq!CORE::$_!) for @ARGV" + abs int push pop map grep sort stat abs ;$ int ;$ push \@@ pop ;\@ map grep sort stat *

      I did not use the "CORE::" prefix when I tested. I too get your results when I do.

      In any case the main point still holds: both map and sort according to your machine (and mine) have an undefined prototype. The fact of an undefined prototype does not provide an explanation of the different behavior. I only wish it were that simple. But thanks, anyway, for your help.

      Best, beth

        sort actually calls a sub. In fact, you can actually pass a sub name. map is like while. No subs are involved.

Log In?
Username:
Password:

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

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

    No recent polls found