Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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]; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527373]
help
Chatterbox?
NodeReaper preheats the oven before tossing in a TV dinner

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2016-12-11 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (169 votes). Check out past polls.