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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Capturing the first and last line of a file ?
by broquaint (Abbot) on May 06, 2003 at 11:13 UTC | |
Re: Capturing the first and last line of a file ?
by Abigail-II (Bishop) on May 06, 2003 at 12:27 UTC | |
Re: Capturing the first and last line of a file ?
by flounder99 (Friar) on May 06, 2003 at 11:24 UTC | |
Re: Capturing the first and last line of a file ?
by nite_man (Deacon) on May 06, 2003 at 11:34 UTC | |
by linux454 (Pilgrim) on May 06, 2003 at 20:07 UTC | |
Re: Capturing the first and last line of a file ?
by BrowserUk (Patriarch) on May 06, 2003 at 13:58 UTC | |
Re: Capturing the first and last line of a file ?
by derby (Abbot) on May 06, 2003 at 13:06 UTC | |
Re: Capturing the first and last line of a file ?
by tos (Deacon) on May 07, 2003 at 08:39 UTC |
Back to
Seekers of Perl Wisdom