in reply to Interpolation in character class

merlyn is right (as he almost always is). However, this sounds like a good case for negative look-behind.
$msg =~ /(\A$dle)(?<!\1)/;

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Interpolation in character class
by Anonymous Monk on Oct 02, 2003 at 17:48 UTC
    That seems to generate a "variable length lookbehind not implemented" error :( Also, I don't understand why we are looking *behind*, don't we want to test the second string character with look *ahead* ? If so, how do we confine the lookahead test to only the *next* character ? Doesn't it look all the way to the end of the string ? Thanks, Scott.
      That'll teach me to blab about features I don't know without testing them first. Yes, positive lookahead would definitely be possible. You'd have to flip your test, though.
      $x = 'aba'; print $x =~ /(.)(?=\1)/ ? "double!\n" : "not double!\n"; $x = 'abba'; print $x =~ /(.)(?=\1)/ ? "double!\n" : "not double!\n"; ---- not double! double!

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.