Hi All,
I'm a relative newbie to Perl and am developing a script to use net::telnet::cisco for labelling a network's switch ports. The problem I have is with this code:
#$name is the new name for the switch port.
#$ports[$i][1] is the existing name of the switch port.
for my $i ( 0..$#ports ){
#If port label is already correct
[red]if ( $name =~ m/$ports[$i][1]/ig ){[/red]
print "Label already correct";
next;
}
#etc...
}
More often than not, $ports[$i][1] = "" and $name = "my_machine" or similar.
Unfortunately, the regular expression thinks that "" eq "my_machine" and so the if condition is entered when it shouldn't be.
Why is this? Could anyone point out what (stupid) mistake I've made with the regular expression?
Many thanks,
James.
I'm a relative newbie to Perl and am developing a script to use net::telnet::cisco for labelling a network's switch ports. The problem I have is with this code:
#$name is the new name for the switch port.
#$ports[$i][1] is the existing name of the switch port.
for my $i ( 0..$#ports ){
#If port label is already correct
[red]if ( $name =~ m/$ports[$i][1]/ig ){[/red]
print "Label already correct";
next;
}
#etc...
}
More often than not, $ports[$i][1] = "" and $name = "my_machine" or similar.
Unfortunately, the regular expression thinks that "" eq "my_machine" and so the if condition is entered when it shouldn't be.
Why is this? Could anyone point out what (stupid) mistake I've made with the regular expression?
Many thanks,
James.