Shlomi Fish 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";

You are using invalid syntax for arrays again. This is getting annoying.

In any case, either of those should do the trick:

        my @new = (map { substr($_, 2) } @old);

Or:

        my @new = map substr( $_, 2 ), @old;


Or:

        my @new = (map { s/\A..//r } @old); # If your perl is recent enough.

Or:

        my @new = map s/\A..//r, @old;


If your Perl is too old you can do:

        my @new = (map { my $x = $_; $x =~ s/\A..//; $x; } @old);

Or:

        s/\A..// for my @new = @old;



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