Hello monks,

Working to finish up an assignment tonight and I have gotten stuck on trying to convert an HoH to an array. I am attempting to extract an @array from the following data structure:

$hash{$w1}{$w2} = { total_counts => $tot_counts, words => { $nw => $count, } }

Basically I want to import all the keys from HoH 'words' (possibly using several '$nw's as keys) into and @array $count times each. I will then use the array function 'rand()' to randomly retrieve and print the content of one of @array's elements.

I have tried to uses the following code, with no sucess:

@newarray = $hash{ $w1 }->{ $w2 }->{ words };

I know that was kind of a stab in the dark, but I am having problems figuring out how to extract each individual value of $nw and use it as a key which is then pushed into an array $count times. My thanks and gratitude to anyone who can show me the way to accomplish this.

-mox

In reply to importing all the values stored in an HoH into an array by chinamox

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.