in reply to Applying regex to array

@fields = qw/this that the_other/; @fields = grep { s/t/j/ } @fields; print join(" ",@fields);
Like that? (ignore all this - I'm dozy. See below)

Replies are listed 'Best First'.
Re^2: Applying regex to array
by davorg (Chancellor) on Nov 24, 2004 at 10:45 UTC

    I don't really understand why you've chosen to use grep here instead of map. With grep you'll lose any elements where the substitution didn't change anything.

    my @fields = qw/this is the_other/; @fields = grep { s/t/j/ } @fields; print "@fields"; # prints "jhis jhe_other" (losing "is")
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg