Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Is there a more efficient way of grabbing the first and last line of a file.
I'm currently doing the following
Reading the entire contents of the file into memory is time consuming and inefficient.#!/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);
Any suggestions?
Back to
Seekers of Perl Wisdom