in reply to Looking for N/A twice

You don't need to explicitly use $_ in a pattern match, and you can use a single regexp (together with FunkyMonk's advice):
if (m{ \bsata\b .*? \bN/A\b .*? \bN/A\b }ix) { ... }
I added the x modifier just to separate the different parts a bit and make it a little more readable (see perlre for more details).

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?

Replies are listed 'Best First'.
Re^2: Looking for N/A twice
by johngg (Canon) on Oct 21, 2007 at 21:50 UTC
    You can use a single regex regardless of order if you use look-ahead assertions.

    $ perl -le ' > $_ = "gjhgjhgjg sata kjhkhkjhkjhkj N/A khkjhkhkhkj N/A"; > print q{ok} if m{(?ix) (?=.*\bn/a\b.+\bn/a\b) (?=.*\bsata\b)};' ok $

    Cheers,

    JohnGG

      This struck me like a thunder:
      m{(?ix) (?=.*\bn/a\b.+\bn/a\b) (?=.*\bsata\b)}
      I thought that the span of application of (?ix) was the stuff inside the two parentheses (just like a contracted form of (?ix:)), but your regex clearly contradicts this. So I turned to the manpage and... it's there, nicely documented! I love this language.

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Io ho capito... ma tu che hai detto?
Re^2: Looking for N/A twice
by FunkyMonk (Bishop) on Oct 21, 2007 at 19:27 UTC
    The OP didn't state the order that the three phrases will appear. Your regexp won't match N/A sata N/A, for example.

    Only neo1491 can say if this is what s?he wants.

      You're right, after re-reading it, I have to admit that I was fooled... by your example :) Good catch anyway, thanks.

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Io ho capito... ma tu che hai detto?