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

If map is meant by design to function as a flow of control token like while and foreach, then I would expect it to be documented as such in perlsyn, which it is not.

Best, beth

Replies are listed 'Best First'.
Re^3: map and return
by Anonymous Monk on Sep 03, 2009 at 11:22 UTC
    What is the prototype for map? It is undef because its arguments cannot be expressed by a prototype because the builtin does not really behave like a Perl function.

      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.

        ..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 *