
rovf
Veteran
Mar 8, 2013, 12:27 AM
Post #2 of 2
(80 views)
|
|
Re: [rudolphe] Perform an action if certain text exist in output
[In reply to]
|
Can't Post
|
|
I think you don't understand yet how an if statement works in Perl, and I strongly suggest that you read the documentation for this (you can get it by typing perldoc perlsyn on the command line). In your case, you have
$nxdomain = "NXDOMAIN"; if ($nxdomain) { ... } which (since the variable $nxdomain never changes) boils down to: In Perl, an expression is considered false if it is neither undef nor the null string ('') nor the string '0' nor numerically zero (0). Everything else is considered true. Since your expression consists of the string "NXDOMAIN", it is considered true and the block is always executed. You probably want to search your line for the occurance of the string NXDOMAIN. There are several ways to do this. One is to used the index function. See perldoc -f index . BTW, I strongly recommend that you put
use strict; use warnings; on top of your code.
|