On Fri, 8 Jun 2001 [EMAIL PROTECTED] wrote:
> Gurus,
> perldoc -f map says,
>
>
>---------------------------------------------------------------------------------------------------------------------
> map BLOCK LIST
> map EXPR,LIST
> Evaluates the BLOCK or EXPR for each element of LIST
> (locally setting `$_' to each element) and returns the
> list value composed of the results of each such
> evaluation. Evaluates BLOCK or EXPR in a list context,
> so each element of LIST may produce zero, one, or more
> elements in the returned value.
>
>---------------------------------------------------------------------------------------------------------------------
>
> Evaluates BLOCK or EXPR in a list context,
> so each element of LIST may produce zero, one, or more
> elements in the returned value.
>
> How is this different from the "return from subroutine" mechanism? There
> the return value is the last expression evaluated ( assuming no explicit
> returns ). Do these 'subroutine blocks' and 'map blocks' have same
> semantics? I read and reread the docs but somehow missing the link, if any
> between the two.
Well it's quite simple actually. A BLOCK of Perl code is a BLOCK of Perl code.
No matter where you put it. Typically anything inside a set of {}'s is a block
of code. So the fact that a subroutine consists of a block of code
sub foo { BLOCK }
and map can use a block of code
map { BLOCK } @list
isn't too surprising.
-- Dave