http://qs1969.pair.com?node_id=11135401

jnarayan81 has asked for the wisdom of the Perl Monks concerning the following question:

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?

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 fi +le '$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;