[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Perl Golf, Ethernet to Token Ring MAC Address



Alistair.McGlinchy@marks-and-spencer.com wrote:

> I "golf"ed the explicit method down to a disappointing 82
> chars using a regular expression with:
> 
> %c=split//,'0018243C425A667E8199A5BDC3DBE7FF';$_=pop;
> s/(.)(.)/$c{$2}$c{$1}/g;print

The "explicit" method I came up with before looking at yours 
used y/// rather than a hash, resulting in 53 characters:

    $_=pop;s/(.)(.)/$2$1/g;y/1-9A-E/84C2A6E195D3B7/;print

> But was amazed that a pack/unpack combination could do better
> at 61 chars.
> 
> for(unpack"B8"x6,pack"H12",pop){print unpack"H*",pack"b8",$_}

My pack/unpack solution was longer than the other, at 56:

    print+map{unpack+H2,pack+B8,unpack+b8,chr hex}pop=~/../g

I'm sure both can be improved.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe