in reply to read a file in both directions

Well, the first part is easy:
open FILE, "path/to/file"; local $/ = "\n\n"; my $first_part = <FILE>;
That would work great if you only needed the first part. But since you want the second part also, unless you are working with HUGE files, I think it's better (more efficient) to read it into memory and then play with it.

open FILE, "path/to/file"; local $/ = undef; my $whole_file = <FILE>; my $first_blank_pos = index($whole_file,"\n\n") die "no blank lines" unless ($first_blank >= 0) my $first_part = substr $whole_file, 0, $first_blank_pos; my $second_part = reverse substr $whole_file, $first_blank_pos;
That will do it all in memory. Do what you will with the parts after that. - d

Replies are listed 'Best First'.
Re^2: (correction)
by dynamo (Chaplain) on May 31, 2006 at 12:02 UTC
    This was originally a correction note, then I realized that I could just edit the original post to be correct, so I did. I don't see a way to delete this post entirely (short of marking it for consideration, which would be making my mistake into more people's problems), so here's what it was.

    ---- original content ---

    oops,

    die "no blank lines" unless ($first_blank > 0)
    should have been:
    die "no blank lines" unless ($first_blank >= 0)