Using map in a void context is bad. Perl expects map to return a list, so it wastes time building up a return list which just gets thrown away. I've heard figures that show it to be 10% slower.
I'd just use for.
s/^|$/"/g for @fields;
I understand this is being worked on for new versions of Perl. There's no reason why map can't work out that it's being called in void context and not build up the return list.
Update: You can safely ignore this advice if you're using Perl 5.8.1 or greater (see perl581delta). Personally, I still think it's an abuse of map when foreach can be used to do the same thing. But YMMV :)
Update (again): Limbic~Region points me at this previous discussion of these points (particularly Abigail's reply here. Having read it thru, it seems to me that tilly sums up my point of view pretty well.
--
< http://www.dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club." -- Chip Salzenberg
|