On Fri, Jun 22, 2001 at 05:25:13PM +0200, Remko Lems wrote:
> for $File (reverse (sort {$All_Scores{$a}{Trimmed} cmp
> $All_Scores{$b}{Trimmed}} keys %All_Scores)) {
> InsertSortedEntries ($File, $All_Scores);
> }
[snip]
> <results>
>
> no
> 11
> 10
> 01
> 00
>
> </results>
>
> That's not exactly what I want. I want to put No at the buttom of that list,
> not at the top. Does somebody has a clue how I can solve this problem?
Make your sort conditional on whether or not it's a number:
sort {
my $a_trmd = $All_Scores{$a}{Trimmed};
my $b_trmd = $All_Scores{$b}{Trimmed};
$a_trmd !~ /\D/ <=> $b_trmd !~ /\D/
|| $a_trmd cmp $b_trmd
} keys(%All_Scores);
The first sort condition, with the regexes, sorts anything numeric-looking
above anything non-numeric-looking. The second sorts numeric values by
string value. Note that the sorting of numbers using cmp only works how you
expect because your numbers are zero-padded.
The sort routine I showed you will produce the results:
no
00
01
10
11
This is because your original sort routine actually produces the results:
00
01
10
11
no
At some point you must be reversing the list, perhaps the
InsertSortedEntries() function is inserting at the beginning of some results
array. This is all under the assumption that your original code doesn't
have a typo. Regardless, you should be able to adapt my code to your
problem.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--