Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
From the perldoc page for map:
<cite> Note that, because C<$_> is a reference into the list value, it can be used to modify the elements of the array. While this is useful and supported, it can cause bizarre results if the LIST is not a named array. Using a regular C<foreach> loop for this purpose would be clearer in most cases. </cite>
so now, what are the cases where map { s/foo/bar/ } @goo is different from for (@goo) { s/foo/bar/ }? what "bizarre results" is it talking about?
<cite> Note that, because C<$_> is a reference into the list value, it can be used to modify the elements of the array. While this is useful and supported, it can cause bizarre results if the LIST is not a named array. Using a regular C<foreach> loop for this purpose would be clearer in most cases. </cite>
so now, what are the cases where map { s/foo/bar/ } @goo is different from for (@goo) { s/foo/bar/ }? what "bizarre results" is it talking about?
|
---|
Replies are listed 'Best First'. | |
---|---|
(chromatic) Re: map and modifying $_
by chromatic (Archbishop) on Jul 14, 2000 at 22:56 UTC | |
Re: map and modifying $_
by Abigail (Deacon) on Jul 14, 2000 at 23:52 UTC | |
Re: map and modifying $_
by Anonymous Monk on Jul 16, 2000 at 18:13 UTC |
Back to
Seekers of Perl Wisdom