in reply to how could I use map here?
You're almost there, map expects a code block followed by a list eg:
@my_array_2 = map { s/^CHOP_ME_OFF_//g } @my_array;map will create a new list then execute the code block for each element in the original list and add the return value of the block to the new list.
The trap to watch out for is that s/// returns a count of the number of substitutions performed (or undef if nothing matched). It does not return the contents of the string after the substitution. So the real answer is:
@my_array_2 = map { s/^CHOP_ME_OFF_//g; $_ } @my_array;Update: Oops, I forgot about the other trap (modifiying the original array) but you already go that from the other answers.
|
|---|