http://qs1969.pair.com?node_id=444783

ghenry has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,

I have a simple subroutine. I would like to try and swap out the foreach loop and use map instead:

sub links { my ($url, @list) = @_; my @return; foreach (@list) { push @return, "$url/$_\n"; } return @return; }

Is this right way to do it?

sub links { my ($url, @list) = @_; my @return = map ("$url/$_\n") @list; return @return; }

I have never used map before and I have read the map function page on http://perldoc.perl.org/functions/map.html, but I don't seem to quite understand.

Thanks.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!