perlquestion
Anonymous Monk
Is there a more efficient way of grabbing the first and last line of a file. <P>
I'm currently doing the following
<code>
#!/usr/bin/perl
use warnings;
use strict;
open (FOO, "test") ||
die "ERROR Unable to open test: $!\n";
my @array = <FOO>;
close FOO;
my $first = shift (@array);
my $last = pop (@array);
</code>
Reading the entire contents of the file into memory is time consuming and inefficient.
<P>
Any suggestions?
29