Link to home
Start Free TrialLog in
Avatar of asago
asago

asked on

reverse data read.

Basically I am reading data in from a flat-file that looks like this:  (format like $itemid|$reportdate|)

0|10/1/1998|
1|11/08/1998|
2|11/10/1998|
3|11/25/1998|
4|12/01/1998|
5|12/05/1998|
6|12/6/1998|
7|1111|

using code like this:

open(adb,$resourcedb);
while (<adb>) {
open (AFILE,"$resourcedb") || die "Content-type: text/html\n\nCan't Open $resourcedb(r): $!\n";
@LINES=<AFILE>;
close(AFILE);
$SIZE=@LINES;
for ($i=0;$i<=$SIZE;$i++) {
   $_=$LINES[$i];
($itemid, $reportdate) = split(/\|/,$_);
print "<A HREF=\"reports/$itemid\">$reportdate\</A><BR>\n";
}
close(adb);
}


BUT - I don't want to read/print from top down, I would prefer it be in reverse order i.e. reading/printing the last record (record 7) first then going back to record 0 - any easy way to do this off the top of your head?

ASKER CERTIFIED SOLUTION
Avatar of b2pi
b2pi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
for( reverse <AFILE> ){
  ($itemid, $reportdate) = split/\|/;
   print qq?<A HREF="reports/$itemid">$reportdate</A><BR>\n?;
}

#but why are you doing this looping over each line of <adb>?