in reply to read a file in both directions
This is a great example of "incomplete specifications."
Assuming "yes" to all three #1 and #3, and "no" to #2 of the above questions, reading the entire file in an array and then reversing the array, and reading it till one reaches the blank line would accomplish the job in a "single pass."
# from the venerable cookbook, recipe 8.4 @lines = reverse <FILE>; foreach $line (@lines) { # do something with $line # until blank line, which happens to be # the first blank line from top }
|
|---|