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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.