in reply to Re3: $1 trap
in thread $1 trap

NO.

This would return "yes", because the regex will match, and thus will return true, even if there is no parens in the regex.

That's why this works:
$_ = "something blah blah"; if (/something/) { print "Ok"; }

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: Re: Re3: $1 trap
by Crackers2 (Parson) on Aug 11, 2003 at 16:46 UTC
    NO. This would return "no", because he's not only comparing the
    result of the regex, but also the value of the submatch:

    "w0rd" =~ /(\d)/ && $1 ? print"Yes": print"no";

    The regex matches, so $1 becomes 0. This makes the condition:

    (true) && 0 ? print"Yes": print"no";

    Which evaluates to false.