in reply to Re: regex and matching
in thread regex and matching

Hey man thanks i understood it. But i have one more problem this code:
$flintstones = "\n or modern stoneage"; if ($flintstones =~ m/(\w*) or \w* \1/){ print "True\n"; }
is returning true even though the conditions if ($flintstones =~ m/(\w*) or \w* \1/) is false

Replies are listed 'Best First'.
Re^3: regex and matching
by CountZero (Bishop) on May 28, 2011 at 06:59 UTC
    You are being mislead by the evil *!

    * means= match ZERO or more of the previous character or group. In this case it is the ZERO that wins. The matched part of the string is ' or modern'.

    Try print "True/ >$1<\n"; and you will see what got matched by the first \w*.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James