in reply to Question about reading specific line in a text file
open (DATAFILE3, $prog); @lines = <DATAFILE3>; close(DATAFILE3); $lines[76] =~ s/^(\S+\s+\S+).*/$1/; print "$lines[76]><br>\n"
Also, it is not a good practice to read the entire file in a single attempt. Think, what happens if the file is huge in size?
Try something like this to avoid reading the file like the above
open (DATAFILE3, $prog); while (<DATAFILE3>) { next if 1 .. 75; # flip-flop operator $line = $_; last; } # $line has the 76th line, do your stuff now. close(DATAFILE3);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Question about reading specific line in a text file
by naikonta (Curate) on Apr 04, 2009 at 07:03 UTC |