Hello,
I have a small .txt database with 5 fields.
Now I want to sort for the 5. field and print that out.
The 5. field is a field with numbers in it (10, 35, 22, 100, ...).
The Database looks like this: field1|field2|field3|field4|number
I test the following:
# Get the settings from the data file.
if(-e $datafile) {
open (DATA, "<$datafile");
LINE: while(<DATA> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$feld5{$data[0]} = $data[4];
$feld1{$data[0]} = $data[0];
close(DATA);
}
}
else {
print "<p>No file found.\n";
exit;
}
my $count=1;
foreach $field (sort { $feld5{$b} <=> $feld5{$a} } keys %feld5) {
if ($count <= 4) {
$output .= "$count. - $feld1{$field} - $feld5{$field}
\n";
}
$count++;
}
print "Content-type: text/html\n\n";
print qq~$output~;
But only the first dataset (first line of the database) will be shown.
I must say to this I'm not a sort funktion professional.
Has anyone a hint for me to do that!?
Another question. What does exact this lines mean (I saw that in a script in GT Forum and try that to sort):
next LINE if (/^#/);
next LINE if (/^\s*$/);
My Perl books won't give me an answer on this 2 problems.
If is it stupid what I did, is it possible to do that in another way?
DelPierro
http://www.simball.de/links_mods/
I have a small .txt database with 5 fields.
Now I want to sort for the 5. field and print that out.
The 5. field is a field with numbers in it (10, 35, 22, 100, ...).
The Database looks like this: field1|field2|field3|field4|number
I test the following:
# Get the settings from the data file.
if(-e $datafile) {
open (DATA, "<$datafile");
LINE: while(<DATA> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$feld5{$data[0]} = $data[4];
$feld1{$data[0]} = $data[0];
close(DATA);
}
}
else {
print "<p>No file found.\n";
exit;
}
my $count=1;
foreach $field (sort { $feld5{$b} <=> $feld5{$a} } keys %feld5) {
if ($count <= 4) {
$output .= "$count. - $feld1{$field} - $feld5{$field}
\n";
}
$count++;
}
print "Content-type: text/html\n\n";
print qq~$output~;
But only the first dataset (first line of the database) will be shown.
I must say to this I'm not a sort funktion professional.
Has anyone a hint for me to do that!?
Another question. What does exact this lines mean (I saw that in a script in GT Forum and try that to sort):
next LINE if (/^#/);
next LINE if (/^\s*$/);
My Perl books won't give me an answer on this 2 problems.
If is it stupid what I did, is it possible to do that in another way?
DelPierro
http://www.simball.de/links_mods/