http://www.perlmonks.org?node_id=831723

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

I have this foreach loop that is supposed to grab some info and append it to a hash of a hash that already exists.

foreach $cmd (keys %fssaCmd) { $opcode = sprintf("%x",$fssaCmd{$cmd}{fixed_pattern}); $apid = sprintf("%x",$ApidBase+$ApidOffset); print ("$cmd, 0x$apid, 0x$opcode\n"); %cmdData = (%cmdData, "0x$apid" => { opcode => "0x$opcode", cmd => $cmd } ) } foreach my $a (sort keys %cmdData) { print $a.", ".$cmdData{$a}{opcode}.", ".$cmdData{$a}{cmd}."\n"; }

The second foreach loop is something I added to see if the first was working. It's not. The print statement in the first loop is working as expected, indicating that the loop is iterating a total of 6 times. However, the second loop is only printing out 2 lines: what was in the hash to begin with, and the last thing added to it by the first loop.

What am I doing wrong here? Why is everything I append to the hash (except for the last thing) going AWOL?

Many thanks!

Kaiti
Swiss Army Nerd