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!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|