Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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!

Swiss Army Nerd

In reply to Getting loopy while appending HoH by jedikaiti

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (9)
    As of 2015-12-01 20:06 GMT
    Find Nodes?
      Voting Booth?

      My keyboard shows this many letters:

      Results (26 votes), past polls