Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Reading Lines from Text file

by ikegami (Pope)
on Feb 02, 2006 at 16:53 UTC ( #527373=note: print w/ replies, xml ) Need Help??


in reply to Reading Lines from Text file

my $first; my $last; { open(my $fh, '<', 'file') or die("Unable to open input file: $!\n"); while (<$fh>) { $first = $_ if not defined $first; $last = $_; } }

or

use File::ReadBackwards (); my $first; my $last; { open(my $fh, '<', 'file') or die("Unable to open input file: $!\n"); $first = <$fh>; } { my $fh = File::ReadBackwards->new('file') or die("Unable to open input file: $!\n"); $last = $fh->readline(); }

or

my $first; my $last; { open(my $fh, '<', 'file') or die("Unable to open input file: $!\n"); ($first, $last) = (<$fh>)[0, -1]; }


Comment on Re: Reading Lines from Text file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-08-30 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls