The $. variable holds the current input line number of the last opened filehandle.
while ( $. < 5 ) { my $line = <DATA>; print "$. -> $line"; } __DATA__ one two three four five six seven
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: how to print first 5 lines of a file
by Ovid
in thread how to print first 5 lines of a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |