perlquestion
Odud
I have a variable that contains, for example, the following:
<BR><BR><CODE>"5.ae.20.b.1c.7"</CODE><BR><BR>(If you're curious it represents the MAC address of a LAN card).<BR>What I want to do is to turn it into the following format:<BR><BR><CODE>"05ae200b1c07"</CODE><BR><BR>i.e. remove the dots and add leading zeroes where the original was only one hex digit. After some experiments I came up the following snippet:<BR><CODE>($mac = $addr) =~ s/(\.|^)([0-9a-f])(?=\.|$)/${1}0$2/g;
$mac =~ s/\.//g;</CODE>This works, but I was wondering if there is a neater way - and in particular can it be done in a single statement?<BR><BR>As usual I look forward to everyone's contributions and suggestions.<BR><BR>[Odud]