Right, that's a point, but the way I look at it it would still work even if s/// was returning the changed string (except, of course, when the returned string was something like zero or an empty string).Really? Then what should s/// return if *no* substitutions took place? undef? That would make
fail to do the right thing most of the time as well - it would only work if the old list only contain strings that would be affected by s///. You would still need to write that as:@new_list = map {s/foo/bar/} @old_list;
most of the time.@new_list = map {s/foo/bar/; $_} @old_list;
In reply to Re^3: A hint about using map
by Anonymous Monk
in thread Turning foreach into map?
by ghenry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |