A Mountain of Perl Books + Python Advocacy

Jake Speed speed at ?.com
Tue May 9 20:43:55 CEST 2000


snowzone5 at hotmail.com (tony summerfelt) wrote in
<slrn8hdj3i.47b.tsummerfelt1 at co146453-a.kico1.on.wave.home.com>: 
[...]
>i think something like the following is pretty hard to beat:
>
>#!/usr/bin/perl
>
>open(in,$ARGV[0]) || die("can't open $ARGV[0]");
>open(out,">$ARGV[1]) || die("can't open $ARGV[1]);
>
>while (<in>)
>{
>  unless($i,{$_}++) {push(@uniq,$_);}
>}
>print out (sort(@uniq));

I can beat it in perl :^) (printing to stdout)

perl -e '$c{$_}++ while <>; print sort(keys %c)'

Of course, that exploits a host of perl niceties:
Iterating over lines of a file, default filehandle 
iterating over @ARGV, undefined hash elements equal
to zero, postfix while, semicolon unnecessary on 
the last statement...

-Speed!



More information about the Python-list mailing list