![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
Re: Reading the contents of a file from the bottom upby roboticus (Chancellor) |
on Nov 24, 2019 at 20:28 UTC ( #11109156=note: print w/replies, xml ) | Need Help?? |
If the file is small enough that it fits comfortably in memory, you could just read the whole thing and then reverse it, like this:
When I run it on itself, I get:
Sometimes a file is too big to handle that way, though that's increasingly rare with modern computers. But if so, you could always use a program (such as tac) that will reverse the file for you, and then you can process the file in order in your code. For one-off jobs, that's the way I'd go. But if you always need to process the files in reverse, I'd use the File::Backwards module that stevieb suggested. ...roboticus When your only tool is a hammer, all problems look like your thumb.
In Section
Seekers of Perl Wisdom
|
|