in reply to Deleting a matching string in an array

You can't match an array, as you try with /@logmessages/.

I think what you want is this:

# if you want @robots to be interpreted as # regexes, delete the map { ... } my $regex = join '|', map { quotemeta $_ } @robots; for (grep { ! /$regex/ } @logmessages){ print OUTFILE $_; }

Note that grep doesn't modify its arguments (normally...), so you have to continue working with the result from grep.

(Update: added the ! in grep, ... ;-)

Replies are listed 'Best First'.
Re^2: Deleting a matching string in an array
by johngg (Canon) on Oct 30, 2007 at 17:04 UTC
    A little piece of code to illustrate naikonta's point.

    $ perl -le ' -> @arr = qw{ abC def gHi JKl }; -> print for grep { s{[A-Z]}{%}g } @arr; -> print q{-} x 25; -> print qq{@arr};' ab% g%i %%l ------------------------- ab% def g%i %%l $

    Cheers,

    JohnGG

Re^2: Deleting a matching string in an array
by naikonta (Curate) on Oct 30, 2007 at 16:15 UTC
    Note that grep doesn't modify its arguments (normally...),
    Are you against Note that $_ is an alias to the list value, so it can be used to modify the elements of the LIST. or you mean something else?

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

      Shameaso seemed to use grep as if he expected it to modify the array, although he didn't modify $_ in grep's block.

      So I thought it was noteworthy that grep doesn't do in-place grepping.

Re^2: Deleting a matching string in an array
by Shamaeso (Initiate) on Oct 30, 2007 at 17:12 UTC
    I appreciate the responses and thanks for giving me an example to work through.
Re^2: Deleting a matching string in an array
by KurtSchwind (Chaplain) on Oct 30, 2007 at 15:27 UTC
    I had a similar solution, but yours is far more elegant. The regex assignment is very nice.
    -- I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.