minixman has asked for the wisdom of the Perl Monks concerning the following question:

All i have a hash of hashes as you can see here from data dumper
16-12-2005 14:51: INFO: DATADUMPER: Displaying sent message queue $VAR1 = 'INFO-3-send'; $VAR2 = { '' => '', '32' => '0.0000', '63' => '0', '17' => '491227329', '200' => '200512', '1' => 'A0017C', '44' => '112.52', '55' => 'EUR', '40' => '2', '999' => 'RT', '57' => 'portwaretrader1', '14' => '0.0000', '20' => '0', '59' => '0', '109' => 'DCN32702', '49' => 'RT', '151' => '1.0000', '10' => '248', '31' => '0.00000000', '150' => '5', '35' => '8', '11' => '3104038', '167' => 'FUT', '6' => '0.00000000', '50' => 'RISKGATEWAY', '39' => '5', '41' => '3104032', '52' => '20051118-07:20:30', '38' => '1.0000', '34' => '24', '56' => 'RT', '37' => '365005888', '54' => '1' }; $VAR3 = 'RT-2-send'; $VAR4 = { '' => '', '32' => '0.0000', '63' => '0', '17' => '490522818', '200' => '200512', '1' => 'A0017C', '44' => '112.49', '55' => 'TG', '40' => '2', '999' => 'CAMPBELL', '57' => 'portwaretrader1', '14' => '0.0000', '20' => '0', '59' => '0', '109' => 'DCN32702', '49' => 'TGV', '151' => '1.0000', '10' => '240', '31' => '0.00000000', '150' => '0', '35' => '8', '11' => '3104037', '167' => 'FUT', '6' => '0.00000000', '50' => 'RISKGATEWAY', '39' => '0', '52' => '20051118-07:19:51', '38' => '1.0000', '34' => '23', '56' => 'TGV', '37' => '365006615', '54' => '1' }; $VAR5 = 'FGH-1-send'; $VAR6 = { '' => '', '32' => '0.0000', '63' => '0', '17' => '489687730', '200' => '200512', '1' => 'A0017C', '44' => '112.49', '55' => 'QWE', '40' => '2', '999' => 'DSF', '57' => 'portwaretrader1', '14' => '0.0000', '20' => '0', '59' => '0', '109' => 'DCN32702', '49' => 'sdfsdf', '151' => '1.0000', '10' => '252', '31' => '0.00000000', '150' => '0', '35' => '8', '11' => '3104032', '167' => 'FUT', '6' => '0.00000000', '50' => 'RISKGATEWAY', '39' => '0', '52' => '20051118-07:19:00', '38' => '1.0000', '34' => '22', '56' => 'DSFSDF', '37' => '365005888', '54' => '1' };
The problem i have is when i try and loop over it with for i get the following.
my $sc = scalar(%messagerecbin); &writelog(1,"Message rec bin = $sc "); foreach my $file (keys %messagerecbin) { if($debug){&writelog(1,"DEBUG: sqlloader_rt: receive Messag +ebin{$file} message: Loading sql below.");} }

Message log below.
16-12-2005 14:51: Message rec bin = 2/8 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{INFO-3-send} + message: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{RT-2-send} m +essage: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{FGH-1-send} +message: Loading sql below. 16-12-2005 14:51: Message rec bin = 2/8 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{INFO-3-send} + message: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{RT-2-send} m +essage: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{FGH-1-send} +message: Loading sql below. 16-12-2005 14:51: Message rec bin = 2/8 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{INFO-3-send} + message: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{RT-2-send} m +essage: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{FGH-1-send} +message: Loading sql below. 16-12-2005 14:51: Message rec bin = 2/8 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{INFO-3-send} + message: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{RT-2-send} m +essage: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{FGH-1-send} +message: Loading sql below. 16-12-2005 14:51: Message rec bin = 2/8 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{INFO-3-send} + message: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{RT-2-send} m +essage: Loading sql below. 16-12-2005 14:51: DEBUG: sqlloader_rt: receive Messagebin{FGH-1-send} +message: Loading sql below.
So it seems to get printed out to many times

jdporter added code tags

Replies are listed 'Best First'.
Re: Hash of hashes returning to many values
by xdg (Monsignor) on Dec 16, 2005 at 15:22 UTC
    my $sc = scalar(%messagerecbin);

    Side note: This tells you about used/allocated buckets in your hash. Do you want the size of your hash? Use this:

    my $sc = scalar keys %messagerecbin;

    As for the "repeats", there's a trailing "}" on your code fragment -- what is that from? The fragment you posted should write four lines --- so the repeats are probably from a loop that is enclosing the fragment. You need to post more code for a diagnosis.

    As a code style question, is there a reason that you're calling &writelog() with an ampersand? It's not necessary in modern Perl unless you need to circumvent prototypes, which you shouldn't be using anyway. (See perlsub for details.)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Hash of hashes returning to many values
by bibliophile (Prior) on Dec 16, 2005 at 15:50 UTC
    Just a quick note on posting style - for long blocks of text (like your message log), you might want to enclose them
    in < readmore > tags. It makes your post shorter (and more likely to be looked at :-)

    Take a look at Writeup Formatting Tips for more information...

    Sorry I can't help with the *actual* question :-)

    --
Re: Hash of hashes returning to many values
by tphyahoo (Vicar) on Dec 16, 2005 at 17:30 UTC
    Can you duplicate the problem in a short script that the monks can execute themselves? That is the way you are most likely to get help... and sometimes just going through the motions to do that solves the problem by itself.
Re: Hash of hashes returning to many values
by eweaver (Sexton) on Dec 16, 2005 at 19:22 UTC
    I am guessing your %messagerecbin = {$VAR1 => $VAR2, $VAR3 => $VAR4, etc.}. If this is the case, the program is doing exactly what you asked it: there are three keys, so it prints each one for a total of 3 prints. If the overall looping of the group of 3 is the problem, it is caused by something higher up in your program which you have not allowed us to see.