I am reading a file and executing a while loop to iteratively run through each line in the file. Inside the while loop I have a if condition which has a nested for loop which does some processes. What happens is that the code exits once the for loop finishes despite the fact that the condition to keep the while loop running is still valid.
my $datafile = "data.txt";
open my $fh, "<", $datafile or die "Failed to open $datafile ($!)";
my $csv = Text::CSV->new() or die "Failed to create Text::CSV object";
my $line = <$fh>;
while ($line = <$fh>)
{
blah blah
blah blah
if ($foo > $cow) {
blah
} elsif ($foo == $cow) {
blah
} 开发者_如何转开发else {
for ($i =1; $i <= $something; $i++) {
blah blah
}
}
}
The problem is the code is not finished going through every line of the data.txt file. The code exits once it finishes with the for loop.
Any insight would be greatly appreciated. Thank you.
I suggest you use the debugger to see what is happening. perldoc perldebug
精彩评论