Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I searach for 2 strings in a file using 'if' statement?
File "XYZ" has -> line1 :"[Message] not in the [mail]". line2 : Nothing is found out [here].
I would like to search for the strings '[Message] and [here]'. How can I search it ?
if ( /][message\]/ && /\[here\]/) is valid ?

Edit by tye thanks to Corion's request

Replies are listed 'Best First'.
Re: strings
by strat (Canon) on Apr 05, 2002 at 10:46 UTC
    I suppose, your Searchexpressions are [message] and [here], as the forum sets them as links.

    If you've got those two lines in one $string, you can do so

    if ($string =~ /\[message\]/ and $string =~ /\[here\]/ ){ ...
    If you have those lines in a String calles $_, then:
    if (/\[message\]/ and /\[here\]/ ){ ...
    If you have got the two lines in two different strings $string1 and $string2, try
    if ($string1 =~ /\[message\]/ and $string2 =~ /\[here\]/ ){ ...

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Re: strings
by mce (Curate) on Apr 05, 2002 at 13:56 UTC
    Hi, as usual with perl, there are milion ways of doing this :-).

    Just to get you on the road

    open(XYZ, "<xyz") or die $!; print "OK\n" if grep({ /Message/ or /here/ } <XYZ> ) >= 2; close(XYZ);


    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium