Click to See Complete Forum and Search --> : Sorting Program Not Working :(


kimskams80
03-06-2009, 11:28 AM
Hi

All was going fine. My program was working fine till now but I don't know why it stopped working now :confused:

This program sorting in descending order a text file with two fields
Key1 3
Key2 4

....

.. and gives the result as

key2 4
Key1 3

..



and has been working fine. I know its a bizarre question but I thought may be someone can guide me. This is the program.
for ($Q_num=851; $Q_num<=855; $Q_num=$Q_num+1) {

print "Processing $Q_num\n";
open $in, "C:/Add_Result_".$Q_num.".txt";
open $out, ">", "C:/Ranked_".$Q_num.".txt";

my @records = map +{
line => $_, score => substr($_, rindex($_, " "))
}, <$in>;
@records = sort {$b->{score} <=> $a->{score}} @records; #to have results in ascending order, just change b to a and a to b in this statement
print {$out} map $_->{line}, @records;
close ($in); close ($out);

}### end of for


Any idea??

Same file almost... I want to sort but now it does not wort but gives the same results as before sorting

Sixtease
03-10-2009, 02:59 AM
The program seems to sort the lines numerically by what is beyond the last comma.

I don't understand exactly what you mean by it having stopped working. You mean that you have exactly the same script, exactly same input file, same perl version on the same platform and yesterday it gave one result and today another? That would be weird.

So is there anything that changed? Like the input file? Please show us the versions where it worked and the one where it no longer does.