kimskams80
03-06-2009, 12:28 PM
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
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