in reply to how could I use map here?
You're running into two pitfalls. A slight rewrite might make it clearer. Consider:
But this won't work. It gives you an array full of integers, and it modifies the contents of @my_array.@my_array_2 = map { s/^CHOP_ME_OFF_//g } @my_array;
In this case, it's better to use substr.
@my_array_2 = map { /^CHOP_ME_OFF_/ ? substr($_, length("CHOP_ME_OFF_")) : $_ } @my_array;
Update: On reflection, might be better off localizing $_
@my_array_2 = map { local $_ = $_; s/^CHOP_ME_OFF_//; $_ } @my_array;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Why localize $_ in the map block?
by pike (Monk) on Feb 07, 2003 at 11:22 UTC | |
by adrianh (Chancellor) on Feb 07, 2003 at 13:59 UTC | |
by pike (Monk) on Feb 10, 2003 at 16:30 UTC | |
by bronto (Priest) on Feb 07, 2003 at 14:26 UTC |