I hope someone can help and I will be very grateful if you can....
I have written a script that scans my website for new documents (type .doc,.xls, .pdf etc), like a focused search. I have used File::Find to find each document and then loaded up an array with that doc's info (age, path, type, section etc..this is for later in the program when I output the HTML and provide doc info for each of the latest.
File::Find executes a sub for each file it finds, so part of this is getting all the info into the array for each file. This array is then pushed into another array at the bottom of this sub so that the next file can be found and loaded into the first array. (sorry if not very clear).
It all works as far as finding the files etc.. but i want to order the final output by the age of the file, which is a variable at @AoA[$i][3], so I'm looping through the top level array and each element in it is another array with all the file info i have collected along the way.
I have tried to extract the age into another array and simply sort that with <=> but although this works I can't tie it back to the values in the original array....
The code for the main bit of the script is below and starts from the 'wanted' sub that is called for each file found by File::Find.
sub wanted {
$filedate = -M $File::Find::name;
$filedetail = int($filedate);
if ($filedetail < $depth) {
if ($_ =~/\.pdf$|\.doc$|\.xls$|\.zip$/){
if ($_ =~/\.pdf$/){$pic = "pdf.gif";}
elsif ($_ =~/\.doc$/){$pic = "word.gif";}
elsif ($_ =~/\.xls$/){$pic ="excel.gif";}
elsif ($_ =~/\.zip$/){$pic ="zip.gif";}
$filecred =(stat($File::Find::name))[9];
$filecred = (gmtime $filecred);
$_ = $File::Find::name;
s/$homepath/$relpath/;
$linker = $_;
@filedir =(split '/', $linker);
$filedee = $filedir[0] . "/" . $filedir[1] . "/" . $filedir[2] . "/" . $filedir[3] . "/" . $filedir[4];
if (/(.*)ta(.*)/){$sect="Trade Section"; }
elsif (/(.*)elexon(.*)/){$sect = "Elexon";}
else {$sect = "general (not E or TA)"; }
$icon = $iconpath . $pic;
if ($filedetail < $since ) { $newby=0; }
@filevals =($count, $filedetail, $sect, $icon, $linker, $filecred, $filedee, $filedir[4], $newby);
if ($sect eq "ELEXON"
{
push (@elexon, [@filevals]);
push (@erank, $filedetail);
} elsif ($sect eq "Trading Arrangements"
{
push (@trade, [@filevals]);
push (@trank, $filedetail);
} else {
push (@others, [@filevals]);
push (@orank, $filedetail);
}
$count ++;
}
}
##
this is an attempt I've made at sorting it but it doesn't work...
@erow = (sort @erank);
for($i=0;$i<@erow;$i++) {
$esorted[$i] = ($erow[$i]{$a} <=> $elexon[$i][1]{$b}) {print "Days since uploaded <b>$esorted[$i][1]</b>";
I know this is long and if your still reading, thanks, but I really am stumped on this and I have only been learning perl for about 2 months now, so PLEASE HELP ME.
Oh and anyone who wants to see the whole script let me know.
I have written a script that scans my website for new documents (type .doc,.xls, .pdf etc), like a focused search. I have used File::Find to find each document and then loaded up an array with that doc's info (age, path, type, section etc..this is for later in the program when I output the HTML and provide doc info for each of the latest.
File::Find executes a sub for each file it finds, so part of this is getting all the info into the array for each file. This array is then pushed into another array at the bottom of this sub so that the next file can be found and loaded into the first array. (sorry if not very clear).
It all works as far as finding the files etc.. but i want to order the final output by the age of the file, which is a variable at @AoA[$i][3], so I'm looping through the top level array and each element in it is another array with all the file info i have collected along the way.
I have tried to extract the age into another array and simply sort that with <=> but although this works I can't tie it back to the values in the original array....
The code for the main bit of the script is below and starts from the 'wanted' sub that is called for each file found by File::Find.
sub wanted {
$filedate = -M $File::Find::name;
$filedetail = int($filedate);
if ($filedetail < $depth) {
if ($_ =~/\.pdf$|\.doc$|\.xls$|\.zip$/){
if ($_ =~/\.pdf$/){$pic = "pdf.gif";}
elsif ($_ =~/\.doc$/){$pic = "word.gif";}
elsif ($_ =~/\.xls$/){$pic ="excel.gif";}
elsif ($_ =~/\.zip$/){$pic ="zip.gif";}
$filecred =(stat($File::Find::name))[9];
$filecred = (gmtime $filecred);
$_ = $File::Find::name;
s/$homepath/$relpath/;
$linker = $_;
@filedir =(split '/', $linker);
$filedee = $filedir[0] . "/" . $filedir[1] . "/" . $filedir[2] . "/" . $filedir[3] . "/" . $filedir[4];
if (/(.*)ta(.*)/){$sect="Trade Section"; }
elsif (/(.*)elexon(.*)/){$sect = "Elexon";}
else {$sect = "general (not E or TA)"; }
$icon = $iconpath . $pic;
if ($filedetail < $since ) { $newby=0; }
@filevals =($count, $filedetail, $sect, $icon, $linker, $filecred, $filedee, $filedir[4], $newby);
if ($sect eq "ELEXON"

push (@elexon, [@filevals]);
push (@erank, $filedetail);
} elsif ($sect eq "Trading Arrangements"

push (@trade, [@filevals]);
push (@trank, $filedetail);
} else {
push (@others, [@filevals]);
push (@orank, $filedetail);
}
$count ++;
}
}
##
this is an attempt I've made at sorting it but it doesn't work...
@erow = (sort @erank);
for($i=0;$i<@erow;$i++) {
$esorted[$i] = ($erow[$i]{$a} <=> $elexon[$i][1]{$b}) {print "Days since uploaded <b>$esorted[$i][1]</b>";
I know this is long and if your still reading, thanks, but I really am stumped on this and I have only been learning perl for about 2 months now, so PLEASE HELP ME.
Oh and anyone who wants to see the whole script let me know.