Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: grep for lines containg two variables

by gjb (Vicar)
on Dec 07, 2005 at 16:41 UTC ( [id://514889]=note: print w/replies, xml ) Need Help??


in reply to grep for lines containg two variables

@interesting_lines = grep {/$string1/ xor /$string2/} @log;
will do nicely.

Hope this helps, -gjb-

Update: apparently I got the question wrong, see the previous answer or for an alternative syntax:

@interesting_lines = grep {/$string1/ and /$string2/} @log;

Replies are listed 'Best First'.
Re^2: grep for lines containg two variables
by ikegami (Patriarch) on Dec 07, 2005 at 16:50 UTC

    When the OP said
    I know the syntax for "or" (code example) but not "and"
    I think he meant
    I know the syntax for "or" (code example) but I don't know the syntax for "and"
    rather than
    I don't know the syntax for "or but not and"

      Anyone else reminded of the Friends episode.

      They don't know that we know they know we know! (Joey just shakes his head. ...

      ---
      my name's not Keith, and I'm not reasonable.
Re^2: grep for lines containg two variables
by reasonablekeith (Deacon) on Dec 07, 2005 at 16:45 UTC
    I'm glad someone else made this mistake, It must be something about how the question is worded because this is also what I thought the OP was after. It's completely wrong though.

    [id://ikegami] got it right.

    ++ for effort anyway :)

    ---
    my name's not Keith, and I'm not reasonable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://514889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found