in reply to Capturing the first and last line of a file ?

Try to use Tie::File module from CPAN. This module represents a text file as a Perl array and the file is not loaded into memory.
tie @array, 'Tie::File', $fname or die "Can't tie $fname: $!"; my $first = shift (@array); # First line of the file my $last = pop (@array); # Last line of the file untie @array;
      
--------------------------------
SV* sv_bless(SV* sv, HV* stash);

Replies are listed 'Best First'.
Re: Re: Capturing the first and last line of a file ?
by linux454 (Pilgrim) on May 06, 2003 at 20:07 UTC
    Here is another way of doing the same thing but without modifying the file.
    tie @array, 'Tie::File', $fname or die "Can't tie $fname: $!"; my ($first,$last) = @array[0,$#array]; untie @array;