[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Processing file backwards?



At 21.43 +0200 98-05-22, Nam-June Joe wrote:
>What is the most straightforward to traverse through an ascii file
>backwards

The most straightforward is, IMHO:

open(IN, $file);
@lines = <IN>;
close IN;
while($line = pop(@lines)) {
   # Do something useful...
}

but you'll need RAM to store the whole file... If you don't have that, you
can always read the whole file, throw away all lines but the last one (or
last few), process that (or them), read the whole file but the lines you've
already processed, throw away all but the few you can handle... but that's
a lot of work for little gain.

Can't you just process the file in the ordinary direction, and then reverse
your output or something?


___Carl_Johan_Berglund_________________________
   Adverb Information
   carl.johan.berglund@adverb.se
   http://www.adverb.se/



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch