I'm trying to sort a pointer file by its contents, which will in turn allow me to display (FileName) in the correct order
.
The pointer file is as follows ..
FileName|CompleteDate|OrderDate|OrderNumber|CustomerName
eg. 123456|27|26|123|Jon Doe
On the page is a option to select how to sort ..
1. By Complete Date
2. By Order Date
3. By Order Number
4. By Amount
5. By Customer Name
--- code ---
if ($Sort eq 1) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byComDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byComDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 2) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byOrderDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byOrderDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 3) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byOrderNumber @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byOrderNumber @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 4) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byPrice @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byPrice @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 5) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byName @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byName @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
sub byComDate {
return $a[1] <=> $b[1];
}
sub byOrderDate {
return $a[2] <=> $b[2];
}
sub byOrderNumber {
return $a[3] <=> $b[3];
}
sub byPrice {
return $a[4] <=> $b[4];
}
sub byName {
return $a[5] cmp $b[5];
}
--- ---
Then the complete files are loaded in order ..
--- ---
for ($i=1;$i<$OrderLine+1;$i++) {
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/$OrderFile[$i].txt"); @ary = <INF>; close(INF);
foreach $line (@ary) {
chomp($line);
($Var,$Result) = split(/\|/,$line);
if ($Var eq "Date") { $Date[$i] = "$Result"; $Date[$i] =~ s/\s+$//; }
if ($Var eq "Time") { $Time[$i] = "$Result"; $Time[$i] =~ s/\s+$//; }
if ($Var eq "ComDate") { $ComDate[$i] = "$Result"; $ComDate[$i] =~ s/\s+$//; }
if ($Var eq "ComTime") { $ComTime[$i] = "$Result"; $ComTime[$i] =~ s/\s+$//; }
if ($Var eq "Order Number") { $OrderNumber[$i] = "$Result"; $OrderNumber[$i] =~ s/\s+$//; }
if ($Var eq "First Name") { $firstname[$i] = "$Result"; $firstname[$i] =~ s/\s+$//; }
if ($Var eq "Middle Name") { $middlename[$i] = "$Result"; $middlename[$i] =~ s/\s+$//; }
if ($Var eq "Last Name") { $lastname[$i] = "$Result"; $lastname[$i] =~ s/\s+$//; }
if ($Var eq "Total Price") { $totalprice[$i] = "$Result"; $totalprice[$i] =~ s/\s+$//; }
}
}
--- ---
Then displayed on the page in a loop..
Problem is the various options to sort are making any difference. Its just displaying from top to bottom or visa versa with reverse, as in the pointer file.
Any help please .. thanks
.
The pointer file is as follows ..
FileName|CompleteDate|OrderDate|OrderNumber|CustomerName
eg. 123456|27|26|123|Jon Doe
On the page is a option to select how to sort ..
1. By Complete Date
2. By Order Date
3. By Order Number
4. By Amount
5. By Customer Name
--- code ---
if ($Sort eq 1) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byComDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byComDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 2) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byOrderDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byOrderDate @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 3) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byOrderNumber @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byOrderNumber @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 4) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byPrice @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byPrice @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
if ($Sort eq 5) {
$OrderLine=0;
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/CompletedLogFile.txt") or dienice(); @orders = <INF>; close (INF);
if ($SortOrder eq "Reverse") {
foreach $line (reverse sort byName @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
}
else { foreach $line (sort byName @orders) { chomp($line); ($order,$CD,$OD,$ON,$PR,$name) = split(/\|/,$line); ;
$OrderLine++; $order =~ s/\s+$//; $OrderFile[$OrderLine] = $order; };
} }
sub byComDate {
return $a[1] <=> $b[1];
}
sub byOrderDate {
return $a[2] <=> $b[2];
}
sub byOrderNumber {
return $a[3] <=> $b[3];
}
sub byPrice {
return $a[4] <=> $b[4];
}
sub byName {
return $a[5] cmp $b[5];
}
--- ---
Then the complete files are loaded in order ..
--- ---
for ($i=1;$i<$OrderLine+1;$i++) {
open (INF,"../cgi-bin/COMPLETED_ORDERS/$Current_Month/$OrderFile[$i].txt"); @ary = <INF>; close(INF);
foreach $line (@ary) {
chomp($line);
($Var,$Result) = split(/\|/,$line);
if ($Var eq "Date") { $Date[$i] = "$Result"; $Date[$i] =~ s/\s+$//; }
if ($Var eq "Time") { $Time[$i] = "$Result"; $Time[$i] =~ s/\s+$//; }
if ($Var eq "ComDate") { $ComDate[$i] = "$Result"; $ComDate[$i] =~ s/\s+$//; }
if ($Var eq "ComTime") { $ComTime[$i] = "$Result"; $ComTime[$i] =~ s/\s+$//; }
if ($Var eq "Order Number") { $OrderNumber[$i] = "$Result"; $OrderNumber[$i] =~ s/\s+$//; }
if ($Var eq "First Name") { $firstname[$i] = "$Result"; $firstname[$i] =~ s/\s+$//; }
if ($Var eq "Middle Name") { $middlename[$i] = "$Result"; $middlename[$i] =~ s/\s+$//; }
if ($Var eq "Last Name") { $lastname[$i] = "$Result"; $lastname[$i] =~ s/\s+$//; }
if ($Var eq "Total Price") { $totalprice[$i] = "$Result"; $totalprice[$i] =~ s/\s+$//; }
}
}
--- ---
Then displayed on the page in a loop..
Problem is the various options to sort are making any difference. Its just displaying from top to bottom or visa versa with reverse, as in the pointer file.
Any help please .. thanks