in reply to Re^6: AND and OR on Regular Expressions
in thread AND and OR on Regular Expressions

So "yes".

You're missing the line that initialises $_ to something "foo" for the second block.

Replies are listed 'Best First'.
Re^8: AND and OR on Regular Expressions
by JavaFan (Canon) on Aug 26, 2009 at 07:36 UTC
    I'm not missing that line. All matches are against the same $_.

      Then look again.

      Are you are your saying your comments are wrong

      /$pat1/ && /$pat2/; # Sets $1 (twice). /$pat1/ && /$pat2/; # Sets $1.
      /^(?=.*?$pat1)(?=.*?$pat2)/; # Sets $1 and $2. /^(?=.*?$pat1)(?=.*?$pat2)/; # Doesn't set $1 or $2.

      And that you repeated 4 lines of code for nothing?

      $pat1 = "(foo)"; $pat2 = "(bar)"; /$pat1/ && /$pat2/; /^(?=.*?$pat1)(?=.*?$pat2)/; $pat1 = "(foo)"; $pat2 = "(baz)"; /$pat1/ && /$pat2/; /^(?=.*?$pat1)(?=.*?$pat2)/;

      I swear I checked that a million times first. I'm blind! Needless to say, it would have been clearer to change $_ instead.

        I'm sorry, but since when does bar equal baz? $_ may not change, but $pat2 does. And that makes all the difference.