in reply to Re: print a determinate line number
in thread print a determinate line number

check the ***magic*** $.

Looks like the OP is already using $.  So I can only guess that the question is how to directly jump to a certain line in a file without going through the content before that line... in which case my reply would be that this could only be done if the lines all have the same length...  Kinda speculative, of course.

Replies are listed 'Best First'.
Re^3: print a determinate line number
by jakobi (Pilgrim) on Oct 06, 2009 at 11:56 UTC

    That would require e.g. seek(), which can be way faster. If the data format allows to use it.

    Maybe that's idiom the opener missed (line-by-line reading of input)

    while(<>){ # <>: used handle is STDIN print if $.==5; # so $. is that handle's line number }

    or do it yourself in say $i

    my $file="/etc/hosts"; my $i=0; # let's use 1-based numbers open(FH,"<",$FILE) or die "dying on $FILE"; while(<FH>){ $i++; print "$i: $_" if $i == 5; }