in reply to Converting MAC Address

How about this?

my $value = "8:0:20:0:2:10"; print join "", map { sprintf "%02s", $_ } split /:/, $value;

or

print sprintf "%02s%02s%02s%02s%02s%02s", split /:/, $value;

Updated as per merlyn's and sauoq's comments below (changed %02d to %02s).

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000001000010100"))'

Replies are listed 'Best First'.
•Re: Re: Converting MAC Address
by merlyn (Sage) on Jan 11, 2003 at 00:05 UTC
Re: Re: Converting MAC Address
by sauoq (Abbot) on Jan 11, 2003 at 00:08 UTC

    Careful. The %d format is for signed integers in decimal. The better choice would be %s.

    -sauoq
    "My two cents aren't worth a dime.";