Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^3: Stupid mistakes I repeatedly makeby jhourcle (Prior) |
on Mar 28, 2005 at 20:36 UTC ( [id://442946]=note: print w/replies, xml ) | Need Help?? |
s/something/else/ for @list;my @new_list = map { ( my $tmp = $_) =~ s/.../.../; $tmp } @list; It's useful only for those times when you don't want to corrupt the original list, for whatever reason You could probably also do: @list = map { s/.../.../; $_ } @list;but you'd take a performance hit for building the list in memory, I would think. (I haven't benchmarked it). Update: Anonymous makes a good point -- faster not to assign it back to itself. (but there is still a performance hit as compared to for/foreach, so just use one of those, and only use map if you don't want to corrupt the original).
In Section
Meditations
|
|