firepro20 firepro20 - 1 year ago 88
Perl Question

Negating a regex pattern match

Is there a way to negate the elsif statement with the following pattern match statement, something like

$ip != $testip

I know that
is only for integers, I just wanted to explain what I want: the same function as
but for strings when pattern matching.

if ( $testip =~ /$ip/ ) {
elsif ( $ip ne $testip ) {

Answer Source

To negate matching, you can use

$testip !~ /$ip/

but there's no need to know, you can just negate the operator

not $testip =~ /$ip/

But why? The else branch is only executed when the if condition returns false.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download