in reply to how could I use map here?

Slight variation.

@array2 = map{ /^(?:chop_me_off)?(.*)$/; $1 } @array;

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re: Re: how could I use map here?
by Hofmator (Curate) on Feb 07, 2003 at 20:42 UTC
    or even simpler: @array2 = map /^(?:chop_me_off)?(.*)/, @array2; m// in list context returns a list of $1, $2, ...

    -- Hofmator

Re: Re: how could I use map here?
by ihb (Deacon) on Feb 08, 2003 at 01:22 UTC

    I stay away from using the above technique using .* as a "get everything" pattern. That is mostly because the /s is almost always forgotten. I tend to forget it less nowadays, but even though I manically think about it when I read other's code I sometimes miss it in my own code.

    In your code above it leads to an undef entry for every value that has a newline somewhere after "chop_me_off" and before the last char in the string. And then again we have the max limit for quantifiers. See perl -Mre=debug -wle '"a" =~ /a*/'.

    ihb