I have a data structure:
{ A [ [0] 0.298024546928301, [1] 0.310437805395979, [2] 0.362849758185986, [3] 0.300927220244308, [4] 0.30014286502788 ], C [ [0] 0.200608102102475, [1] 0.274657378132592, [2] 0.192625882771276, [3] 0.162815453143259, [4] 0.158490613195079 ], G [ [0] 0.217826947179901, [1] 0.132847137086947, [2] 0.206439273801657, [3] 0.188858010150455, [4] 0.253229183805833 ], T [ [0] 0.28354040378812, [1] 0.282057679385473, [2] 0.238085085241806, [3] 0.347398866718639, [4] 0.288136438478111 ] }

And I want to access all of the main values at once, and possibly store them in separate arrays, for example:

$arrayA = (0.298024546928301, 0.310437805395979, 0.362849758185986, 0.300927220244308, 0.30014286502788)

For the values attached to the 'A' key. I can do this either by iterating over the hash and pushing each value into an array or via:

$test{'A'}[0,1,2,3];

However the number of values is variable and i'd rather not have to specify 0,1,2,3,4,5 etc. but rather just a range based on a variable. However when I do:

$test{'A'}[0..$value];

or:

$test{'A'}[0..3];

It no longer works. Why is that and how can I accomplish this?


In reply to Extract hash values without a loop by TJCooper

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.