in reply to read a file in both directions
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 $/ = "\n\n"; my $first_part = <FILE>;
That will do it all in memory. Do what you will with the parts after that. - dopen 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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: (correction)
by dynamo (Chaplain) on May 31, 2006 at 12:02 UTC |