Shlomi Fish wrote:

thanks for your answer. See below for my response.

On Wed, 5 Sep 2012 09:54:11 -0400
Shawn H Corey<shawnhco...@gmail.com>  wrote:

On Wed, 5 Sep 2012 14:33:13 +0100
jet speed<speedj...@googlemail.com>  wrote:

i have an regx question. i have the array contents, now i want to
remove the first 2 characters (fc) of each element in the array and
store it in a second array ex: @array2

@array ="fc20/1, fc30/22, fc40/3, fc20/1";

output

@array2 ="20/1, 30/22, 40/3, 20/1";

please advice.

It would be helpful if you posted actual Perl code.

Try:

     # remove the first 2 characters from every element of the array
     my @array2 = map { s/^..//msx } @array1;

This code is wrong in two respects:

1. the map clause will return the return value of the s/// subtitution and will 
modify
the original array in place:

Correct.

2. A minor problem of semantics is that under /m "^" matches any start of line,

Only if the /g option is also used AND the strings have embedded newlines.

so \A is preferable.

Without the /g option ^ and \A do exactly the same thing.




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to