Sorry, that was with record oriented files. Now days most file systems are continuous streams of characters, and the record boundaries are defined by context. The normal operation to read from a file does so in the forward direction and advances the pointer by that same amount. This is the problem. if you desire to read a file in the reverse direction, you must do so with forward semanticts[sp?]. This means you must "backup" a record, read the record just backed over, then "backup" again. It isn't easy, but it can be done. Others have indicated there is a Perl module to help you in this, and if done correctly ("tie" to a file handle comes to mind) it might even seem like a normal operation.
That being said, reading in the reverse direction isn't commonly done, as there are usually better ways to do the same thing. Reading the records into a hash, and operating on them that way is probably a "better idea". Also consider the original dataset. It might be better formatted at the source to eliminate the need to do the fancy dance with the data. A good look at "why" you need to access the data in this manner might pay off better in the long run.
Good luck!
In reply to Re: read a file in both directions
by herby1620
in thread read a file in both directions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |