Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Keep It Simple, Stupid
 
PerlMonks  

Re: grep for lines containg two variables

by gjb (Vicar)
on Dec 07, 2005 at 16:41 UTC ( #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;


Comment on Re: grep for lines containg two variables
Select or Download Code
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.

    ikegami got it right.

    ++ for effort anyway :)

    ---
    my name's not Keith, and I'm not reasonable.
Re^2: grep for lines containg two variables
by ikegami (Pope) 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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2014-04-16 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls