[plug] [Perl] sorign arrays based on scalar value - Golf anyo ne?
Carl Gherardi
C.Gherardi at curtin.edu.au
Fri Nov 15 17:09:55 WST 2002
Golf anyone?
I'll put up an initial score, there must be better players out there than
me.
Assuming $id is the first entry in the file, from the initial mail that
looked to be right.
sub resort(){ 13
my($i,$o)=($_[0],$_[1]); 24
open(I,"<$i")or die; 19
@a=<I>; 07
close(I); 09
@b=sort{$b <=> $a}@a; 21
open(O,">$o")or die; 20
print O @b; 11
close(O); 09
} 01
-----------
134
Close enough to what I score when I play usually!
Be a lot shorter using
system "sort -gro $out $in";
Scores 28 and gives the same result, breaks the rules of golf though
Carl
More information about the plug
mailing list