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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Dealing with nextline of a file
by eyepopslikeamosquito (Archbishop) on Jul 27, 2021 at 11:02 UTC | |
Re: Dealing with nextline of a file
by Corion (Patriarch) on Jul 27, 2021 at 08:48 UTC | |
| |
Re: Dealing with nextline of a file
by LanX (Saint) on Jul 27, 2021 at 10:12 UTC | |
Re: Dealing with nextline of a file
by Marshall (Canon) on Jul 28, 2021 at 05:43 UTC | |
Re: Dealing with nextline of a file
by BillKSmith (Monsignor) on Jul 28, 2021 at 14:22 UTC | |
| |
Re: Dealing with nextline of a file
by tybalt89 (Monsignor) on Jul 28, 2021 at 01:17 UTC | |
Re: Dealing with nextline of a file
by fishy (Friar) on Jul 31, 2021 at 20:36 UTC |
Back to
Seekers of Perl Wisdom