Gossamer Forum
Home : General : Perl Programming :

Sort problem

Quote Reply
Sort problem
I am a Perl newbie who (until I started to try to sort my flatfile database) was able to modify what I found in books and in tutorials.

I have pieced together a Perl program that will allow me to add, edit, and delete records in a pipe-delimited database. However, I cannot formulate a correct sort routine.

Here is the relevant portion of my code:

Code:


open (DATABASE,">$database");
@DB=<DATABASE>;
foreach $rec (@DATAB){
chomp($rec);
($name,$company,$score)=split(/\|/,$rec);
if ($name eq $input{'name'} && $company eq $input{'company'} && $score eq $input{'score'}){
print DATABASE "$input{'nname'}|$input{'ncompany'}|$input{'nscore'}\n";
}else{
print DATABASE "$name|$company|$score\n";
}
}
close (DATABASE);

@DATABASE = sort {
$score{$b} <=> $score{$a} or $company{$a} cmp $company{$b} or $name{$a} cmp $name{$b}
} @DATAB;

foreach $rec (@DATABASE){
chomp($rec);
($name,$company,$score)=split(/\|/,$rec);
print DATABASE "$name|$company|$score\n";
}

Can anyone please tell me what I am screwing up? (This code will run without error, but it does not sort.)
Subject Author Views Date
Thread Sort problem sws_mark 6312 Apr 25, 2003, 11:09 AM
Thread Re: [sws_mark] Sort problem
Paul 6144 Apr 25, 2003, 11:52 AM
Post Re: [Paul] Sort problem
fuzzy logic 6144 Apr 25, 2003, 12:21 PM
Thread Re: [Paul] Sort problem
sws_mark 6121 Apr 25, 2003, 12:38 PM
Thread Re: [sws_mark] Sort problem
Paul 6122 Apr 25, 2003, 12:42 PM
Thread Re: [Paul] Sort problem
sws_mark 6111 Apr 25, 2003, 1:05 PM
Thread Re: [sws_mark] Sort problem
fuzzy logic 6106 Apr 25, 2003, 1:47 PM
Post Re: [fuzzy thoughts] Sort problem
sws_mark 6111 Apr 25, 2003, 2:12 PM
Thread Re: [fuzzy thoughts] Sort problem
Paul 6112 Apr 25, 2003, 3:28 PM
Post Re: [Paul] Sort problem
fuzzy logic 6093 Apr 25, 2003, 11:09 PM