Without seeing more of your code, we can only speculate why you are not always catching the last payment. My best guess would be that there is a path through the code that bypasses your increment.
You might be able to simplify your code slightly as
my $numpayments = scalar keys ..... ... if (! --$numpayments) {lastpayments =1} ... if ( $lastpayments ){ print "last record\n"; };
Or even simpler
my $numpayments = scalar keys %..... .... --$numpayments; ... if(! $numpayments ) { print "Last record\n"; }
If you need to remember the $numpayments value for other uses, just make a copy and decrement that.
Using a single var and --, will eliminate a couple of possible modes of failure. It won't necessarially fix your problem, but i t might help highlight where it is.
If not, come back and post a bit more code.
In reply to Re: keeping track of the current element in a multi-dimensional hash
by BrowserUk
in thread keeping track of the current element in a multi-dimensional hash
by GhodMode
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |