I have code to build a hash of array references. It seems that when I add the array reference to the hash, it does not always update the number of elements in the hash correctly. I can make this same kind of call again and it seems to add in the array refernce. Does anyone know of an issue with adding array references to a hash. My code snippet is as follows:
foreach $key (keys %extractDataFunctionHash) { # Loop over the data in each lines array and extract the specifi +c # data for that sample. Call the function defined for that key. # #printf("calling has function: %s\n", $key); $extractDataFunctionHash{$key}($key, $DNRef, $EDHRef); $numInHash = %$EDHRef; printf("\nPASS: Data extraction complete for %s...%d items in ha +sh.\n", $key, $numInHash); }
The function references in the function hash each do basically the same work other than some simple formatting differences. Each one at the end of its array data collection/creation has the following statement:
$EDHRef->{$key} = \@extractedLinesArray;
When I print out the number of elements in the hash each time in the loop it indicates 1 element, then 1 element, then 2, then 3, then 4, then 5. There should be 6 elements in the hash. I have put printfs all around this line of code. The first function (there are 6 calls to 6 difference functions in the function hash) call adds 1 element in the hash and the number in hash (1) is correct. On the second call, it indicates there is only 1 element in the hash again. Afterwards it increments as it should up to 5 instead of 6. I am totally confused and need help. thanks...

In reply to hashes of array references by tobyperl

Title:
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, details, 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, summary, 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.