Web Development

General discussion


perl patternt comparison

By rjsaulakh ·
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

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by corey1981 In reply to perl patternt comparison

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;

Related Discussions

Related Forums