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

RE: [FWP] comm Golf



> 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)whi
le$a&&$b;print$a,<A>,$\="\t",$b,<B>'

Nathan Torkington suggested 
>  perl -e'open A,shift;$h{$_}=1 while<A>;$h{$_}|=2
while<>;map{print"\t"x($h{$_}-1),$_}sort keys%h'
>  perl -e'$h{$_}|=2-@ARGV while<>;print"\t"x($h{$_}-1),$_ for sort keys%h'
>  perl -ne'$h{$_}|=2-@ARGV;END{print"\t"x($h{$_}-1),$_ for sort keys%h}'

As much as I like the techniques used here, Nathan's versions don't print
the same output as as Tim's. For eg, Nathan's doesn't deal with duplicate
entries in the one of the source files, nor does it print the output in the
same order as the input.

I can't see how to use a hash and still preserve the correct order of both
input files. Here's my current best at 131. But it seems extremely beatable
with three "print"s and two "shift"s:

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

Cheers,

Alistair
__________________________________________________________________________________________

Registered Office:
Marks and Spencer plc
Michael House, Baker Street,
London, W1A 1DN
Registered No. 214436 in England and Wales.

Telephone  (020) 7935 4422
Facsimile  (020) 7487 2670

www.marks-and-spencer.com

This e-mail is Confidential. If you received it by mistake, please let us know and then
delete it from your system; you should not copy, disclose, or distribute its contents to
anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.
___________________________________________________________________________________________

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