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

Re: Reading Lines from Text file

by ikegami (Patriarch)
on Feb 02, 2006 at 16:53 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found