I want to read a text file data.txt using read.
I would like to read the first four integers of each line at a time.
data.txt
line1 0101020102
line2 2010201001
line3 0201010201
The line1 etc. are part of the file.
This is what I could do up to now
Perl
my $data;
my $IN;
my $n = 0;
$line = 1;
open($IN, '<', "data.txt") or die " Error";
while ( $line != 0 ) {
seek($IN, 6, SEEK_SET);
$line = read($IN, $data, 4);
seek($IN, 0, SEEK_SET);
}
The problem is that using this while loop, Perl keeps reading the first line in an infinite loop.
How can I deal with this problem?
seek()to the beginning of the file after every read?readis a good idea here (it isn't) or are you simply experimenting with the operator?