perlquestion
jnarayan81
<p> When I tried to read nextline, the pointer in the while loop reads two lines at a time. Is there another creative way to deal with the file's next line?</p>
<code>
use strict;
use warnings;
my %store; my $nextline; my $cnt=1;
my $filename = "$ARGV[0]";
open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!";
while (my $row = <$fh>) {
chomp $row;
my @tmp = split /\s+/, $row;
$nextline = <$fh>; chomp $nextline;
my @nexttmp = split /\s+/, $nextline;
print "$row\t$cnt\n";
if ($tmp[0] ne $nexttmp[0]) {
$cnt++;
}
print "$nextline\t$cnt\n";
}
close $filename;
</code>