keiusui has asked for the wisdom of the Perl Monks concerning the following question:

Why does the following code return "not found!"?
$a = 'dog'; $b = 'doghouse'; if($a =~ /$b/){print "<p>found";} else{print "<p>not found!";}

Thank you so much.

Update: Nevermind! I figured it out. Thanks so much.

Replies are listed 'Best First'.
Re: searching a string
by Sidhekin (Priest) on Jul 07, 2006 at 03:07 UTC

    Because the string 'doghouse' is not found in the string 'dog', and because you aren't returning the strings, but rather printing them ...

    (While I'm at it ... don't use $a and $b for other than sorting. They're "special".)

    This would return "found":

    $A = 'dog'; $B = 'doghouse'; if($B =~ /$A/){ return "found"; } else{ return "not found!"; }

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!