in reply to read a file in both directions

This is a great example of "incomplete specifications."

  1. Is the file only "text" file?
  2. Are there more blank lines after the "first" blank line?
  3. Is the file small enough that available memory is not going to be an issue?
Knowing answers to the above question would allow creating a suitable, fast, and reliable method for doing the job.

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 }
--

when small people start casting long shadows, it is time to go to bed