U
Uri Guttman
MG> Of course, there is a "map" equivalent, too:
MG> map { print "$_\n"; } @ARGV;
MG> I find that to be the most elegant way of looping through arrays. Of
MG> course, if you need the global $_ variable, for instance for reading a
MG> file, this trick is not applicable.
and that is considered to be very poor perl code. it is using map in a
void context. in older perls it would actually build up a list and throw
it away wasting ram and cpu. newer perls don't do that but it it still
poor style. map is for making a NEW LIST from an existing list. so it
should have output that is used. ignoring the output will confuse the
reader. and perl HAS a similar thing that is what you want: the foreach
modifier.
print "$_\n" foreach @ARGV ;
don't use map in a void context!
uri
MG> map { print "$_\n"; } @ARGV;
MG> I find that to be the most elegant way of looping through arrays. Of
MG> course, if you need the global $_ variable, for instance for reading a
MG> file, this trick is not applicable.
and that is considered to be very poor perl code. it is using map in a
void context. in older perls it would actually build up a list and throw
it away wasting ram and cpu. newer perls don't do that but it it still
poor style. map is for making a NEW LIST from an existing list. so it
should have output that is used. ignoring the output will confuse the
reader. and perl HAS a similar thing that is what you want: the foreach
modifier.
print "$_\n" foreach @ARGV ;
don't use map in a void context!
uri