in reply to Re: Re: Converting MAC Address
in thread Converting MAC Address

In the vein of TMTOWTDI, I think this is clearer:

my $mac = "0:0A:0C:B:B8:F"; my @mac = split /:/, $mac; $mac = join ':', map {sprintf '%02X', hex $_};
(BTW, this will reformat things that aren't even close to being valid MACs into things that look a little closer, but still aren't. For example, 'this::isn't:a:mac:foo' would become '00:00:0A:00:0F'.)


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re: Re: Re: Re: Converting MAC Address
by poj (Abbot) on Jan 11, 2003 at 10:49 UTC
    correction$mac = join ':', map {sprintf '%02X', hex $_} @mac; # @mac added poj