On Sat, 17 Nov 2001 20:28:19 +0100, in perl.modules you wrote:

> Brian McCauley wrote:
> > 
> >                                    Unlike map and grep the elements
> >     of LIST are not altered.
>
> Please excuse my stupid question :-)
> 
> What's the difference to the map function.

See above :)

> What you've written above, would I have written as
> @foo = map { s/\s+/ /g } @bar;

$_ is an alias to the original values inside map and grep, so your code
above would have modified @bar. An equivalent using map might be

    @foo = map { my $x = $_; $x =~ s/\s+/ /g; $x; } @bar;

, but that's more typing. As Brian said, it's possible to provide the
same functionality already; 'apply' just saves you some typing.

Cheers,
Philip

Reply via email to