On Jun 20, 7:42 am, [EMAIL PROTECTED] (Alok Nath) wrote:

>         Is it possible to read a particular line by line number ?
>
>         For e.g reading line 3 from a file.
>
>         I don't want to read each line and count.

You don't have to count.  Perl counts for you. The current line number
is always stored in the $. variable.
my $third;
while (<$fh>) {
   if ($. == 3) {
       $third = $_;
       last;
   }
}

Alternatively, consider the Tie::File module:
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;
tie my @lines, 'Tie::File', "file.txt" or die $!;
my $third = $lines[2];
__END__

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to