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

Re: [FWP] comm Golf



>>>>> "NT" == Nathan Torkington <gnat@frii.com> writes:
NT> tayers@bridge.com writes:
>> 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>'

NT> My entries, showing the evolution of my techniques:

NT>   perl -e'open A,shift;$h{$_}=1 while<A>;$h{$_}|=2 while<>;map{print"\t"x($h{$_}-1),$_}sort keys%h'

NT>   perl -e'$h{$_}|=2-@ARGV while<>;print"\t"x($h{$_}-1),$_ for sort keys%h'

NT>   perl -ne'$h{$_}|=2-@ARGV;END{print"\t"x($h{$_}-1),$_ for sort keys%h}'

Um. Err. Uh. Those are excellent! (I'll happily accept the new feature
of "uniquify-ing" the file for such insight!) I had the idea of the
hash but couldn't figure out how to track the number of tabs.

NT> Curse you for making me lose the morning :-)

I'm really sorry about that, but I really appreciate the
examples. Showing your evolution is great help as I strive to become
smarter than a rock.

>>> And "M" == Alistair McGlinchy
>>> <Alistair.McGlinchy@marks-and-spencer.com> with help from
>>> Larry Rosler, Peter Scott and Stephen Zander produce:

M> perl -e'open B,pop;@a=<>;for(<B>){print shift@a while$a[0]lt$_&&@a;print"\t",$a[0]eq$_?"\t".shift@a:$_}print@a'

Fantastic! I suppose my only consolation is that my version still
works if both files have 70 kajillion lines. ;-)

I'm in the lucky position of leaving at the crack of dawn for vacation
in Hawaii. TTYL.

Hope you have a very nice day, :-)
Tim Ayers (tayers@bridge.com)


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