in reply to Re: Saving Results of a while loop
in thread Saving Results of a while loop
Using \Q and \E ensure that no matter what $ip has in it, it will be matched very literally. You could also take this approach:$ip = "192.168.3.5"; # ... if ($line =~ /\b\Q$ip\E\b/) { # ... }
This makes sure that $ip is "regex-ready" before being used, by virtue of the qr() function.$ip = qr("192.168.3.5"); # ... if ($line =~ /\b$ip\b/) { # ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re3: Saving Results of a while loop
by Hofmator (Curate) on Aug 01, 2001 at 20:02 UTC | |
by tadman (Prior) on Aug 01, 2001 at 20:10 UTC |