Code:
$_ = "Sample sentence with 00-B0-D0-86-BB-F7 MAC address in the middle";
my ($a, $mac, $b) =
split('/([0-9A-F]{2}[:-]){5}([0-9A-F]{2})/', $_);
print $mac;
print "\n";
For some reason $mac is always empty, and I don’t know why.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you supply
splitwith a string as the first argument it will split on that string as if it were a regex.Is really a DWIM of:
So your code of:
Really means
Also you want
splitto save the value that it matches on, so you want the whole match to be in().Since you appear to only use
$macyou don’t have to usesplit.