perl patternt comparison
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
Web Development
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
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.
Sort by Trending