Discussion Locked

perl patternt comparison

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i have strings say like $a
$a = '00:d0:cf:04:67:34' i want to compare it with some other values . let me know how can i do it . tell me how can i remove the single quotes

1 reply

by corey1981

Could you please elaborate on what you mean by "compare"? If you mean see if it matches another variable that is a mac address, and see if they match:

if ($a =~ /$othermac/){
print "They match\n";
} else {
print "They do NOT match\n";
}

If you want to check to make sure that $a is a mac address (in cisco format) it would be:
if ($a =~ /((([a-f\d]{4}\.){3})([a-f\d]{4}))/i ) {
print "This is a mac address \n";
} else {
print "This is NOT a mac address! \n";
}

Remove all single quotes contained in that variable:
$a =~ s/'//g;

This discussion is closed to new replies.