This is ridiculously easy if you don't care about memory:
open($handle, 'test.dat');
while (<$handle>) {
chomp; last if !$_;
}
chomp(@data = <$handle>);
close($handle);
for (reverse @data) {
print $_, "\n";
}
But you may want to use a more memory-efficient method:
open($handle, 'test.dat');
while (<$handle>) {
chomp; last if !$_;
}
while (<$handle>) {
chomp; push @data, $_;
}
close($handle);
for ($i = $#data; $i > -1; $i--) {
print $data[$i], "\n";
}
And then there's always the really memory-efficient method (which I'm not supplying code for here), which would involve finding the position in the file of the first blank line (keep track of current position by adding up line lengths), then going to the end of the file and working back in chunks of x bytes. This gets a lot more messy and complicated, and I sadly don't have time right now to write up a working code sample.