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

[FWP] comm Golf



I've enjoyed grok'ing the Golf shots lately. Wanting to practice a
little I pulled out my Llama book and tried some of the
exercises. Several were fun for me, but too easy for this group so
last night I tried implementing the UNIX 'comm' command without options.

The best I came up with was

perl -e'open A,$ARGV[0];open B,$ARGV[1];$a=<A>;$b=<B>;($a ne$b?$a lt$b?($_=$a,$a=<A>):($_="\t$b",$b=<B>):($_="\t\t$a",$a=<A>,$b=<B>),print)while$a&&$b;print$a,<A>,$\="\t",$b,<B>'

A long golf shot to be sure. :-/ Having to call open() a couple times
doesn't help the stroke count. I tried a variation which slurped the
files all at once, but that was much longer.

I was wondering how to really do it. Thanks. 

Hope you have a very nice day, :-)
Tim Ayers


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