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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting loopy while appending HoH
by toolic (Bishop) on Mar 29, 2010 at 23:23 UTC | |
by jedikaiti (Hermit) on Mar 29, 2010 at 23:33 UTC | |
|
Re: Getting loopy while appending HoH
by GrandFather (Saint) on Mar 29, 2010 at 23:15 UTC | |
by jedikaiti (Hermit) on Mar 30, 2010 at 15:59 UTC | |
by almut (Canon) on Mar 30, 2010 at 17:19 UTC | |
by GrandFather (Saint) on Mar 30, 2010 at 20:05 UTC | |
|
Re: Getting loopy while appending HoH
by Anonymous Monk on Mar 29, 2010 at 23:04 UTC |