in reply to 'while', 'foreach' not in perlfunc

Oddly enough, searching at perl.org in index-functions does not turn up documentation for while, nor for foreach. The other Perl iterative constructs, grep and map are there, though.

I personally believe it's not odd at all: it is to be expected, since map and grep are not simply "iterative constructs" but actual functions, whereas while and for are flow control statements or statement modifiers. I believe that in Perl 6 they will become (more akin to) real functions, but that's not the case as of now.

--
If you can't understand the incipit, then please check the IPB Campaign.

Replies are listed 'Best First'.
Re^2: 'while', 'foreach' not in perlfunc (Perl 6)
by moritz (Cardinal) on Jun 14, 2008 at 14:20 UTC
    I believe that in Perl 6 they will become (more akin to) real functions, but that's not the case as of now.
    They will never be quite like ordinary functions, because they violate the "no two terms in a row":
    # while: while $cond { $statements } # ordinary funtion: my_while $cond, { $statements }; # allowed in ordinary functions: my_while $cond, █ # not allowed in builtin while: while $cond █

    while is parsed like this in STD.pm:

    rule statement_control:while {\ <sym> [ <?before '(' [[my]? '$'\w+ '=']? '<' '$'?\w+ '>' ')'> #' <.panic: "This appears to be Perl 5 code"> ]? <EXPR> {*} #= exp +r <pblock> {*} #= blo +ck {*} }

    So it's still special-cased. (It would be even without the check for Perl 5 constructs)