Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   Determining a negative match (http://www.programmingforums.org/showthread.php?t=10459)

Blackwolf189 Jun 20th, 2006 2:51 PM

Determining a negative match
 
Hey i have a program where i needed to determine if something didnt match.
I originally tried using !=~ but no matter how many times i entered the string to match, it wouldnt work. i eventually replaced it with the not on the outside of the match and it now works. I would like to know why did !=~ fail to do what i wanted.

This doesnt Work
:


$k = ""
while ($k !=~ /hello/i)
{
    $k = <STDIN>;
}


This Works
:

$k = ""
while (!($k =~ /hello/i))
{
    $k = <STDIN>;
}


My question is whats the difference

Arevos Jun 20th, 2006 2:57 PM

It's been a while since I've used perl, but I believe !~ is the correct operator to use.

Infinite Recursion Jun 20th, 2006 3:13 PM

Yep, !~ would work. The other issue was probably due to operator precedence, etc.


All times are GMT -5. The time now is 8:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC