in reply to Cantor's Revenge Matching

It seems odd to me that ÑÑ =~ Ñ. would match but Ñ. =~ ÑÑ would not. Here's and even simpler version that shows that Ñ =~ . matches and . =~ Ñ does not.

. matches any character (except \n by default) so m/Ñ./ matches a Ñ followed by any character, which ÑÑ is. m/ÑÑ/ matches only ÑÑ, which Ñ. is not. The difference is that in a regex, . has special meaning, while in a string, it doesn't.

Replies are listed 'Best First'.
Re: Re: Cantor's Revenge Matching
by terrencebrown (Acolyte) on May 01, 2003 at 17:22 UTC

    So the value in $h is being used as regex code. Somehow I thought the pattern needed to pre-compiled using qr//.

    $h =  qr/../;

    Thank you so much for the answer.

      Correct. Regexen go through double-quotish interpolation (with a few exceptions, like using single quotes as the delimiters) before being passed on to the regex engine, so you can say stuff like:
      my $foo = 'first part'; my $anything = '.*'; my $bar = 'last part'; $_ =~ /$foo$anything$bar/;
      and have it mean the same as:
      $_ =~ /first part.*last part/;