If you can post your code in a block (or a subset to demonstrate the problem), this might make things clearer. By putting all of your code together, I get the following:
for ( keys %{$payment{$check_number}} ) { my $numpayment = scalar ( keys %{$payment{$check_number}{$account}} +); for ( keys %{$payment{$check_number}{$account} ) { my $last_payment = 0; if ( ++$payment_count == $numpayments ) { $last_payment = 1 }; if ( $last_payment == 1 ) { print "last record\n"; print FH "\n"; }
I don't think that can be correct as both of your for loops are assinging to $_, thus having your second one trounce on the value of the first. Also, this line is problematic:
if ( ++$payment_count == $numpayments )
As a general rule, you don't want to autoincrement variables within another expression. You are not guaranteed that it will behave the way you expect. If possible, one way to correct that:
$payment_count++; if ( $payment_count == $numpayments )
It may not effect the program, but it's easier to read. If you can post your code a bit more clearly, we may be able to see the issue (or maybe someone else sees it now, I don't). Since the code above doesn't actually use the $_ variable that you're stepping on, I can only assume that there's more here than meets the monitor.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to Re: keeping track of the current element in a multi-dimensional hash
by Ovid
in thread keeping track of the current element in a multi-dimensional hash
by GhodMode
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |