http://qs321.pair.com?node_id=212613


in reply to How do I seek to a certain position in a file?

GhodMode said:
my @array = <FILE>; close FILE; # Print line 10 print $array[10];

Not quite. That prints line 11. I would do something like this:

my $findline = 10; while (<FILE>) { next unless $. == $findline; # .. do something last; #don't read any more }

For the original question "do something" would probably be a seek backwards to the desired char, or perhaps more sensibly, stop the line before and seek forwards.

for more info on $. and friends, see perldoc perlvar

-- simonflk