Basically, when you save an array or hash as elements of a hash, you have to store the array ref or hash ref.

See the code and comments:

use strict; #for better practice use warnings;#same as above my @test = ( qw / bing bong bang / ); print '['.$test[2].'] ['.$test[1].'] ['.$test[0]."]\n"; my %bits;#explicitly declare your variables $bits{'one'}= \@test;#assign the array ref, not the flattened array it +self. my @new = @{$bits{'one'}};#now deref it, so you get the flattened arr +ay back. print '['.$new[2].'] ['.$new[1].'] ['.$new[0]."]\n";

A even better way, is to use the array ref directly, instead of falttening it and copying the entire array. When the array is big, that gives you bad performance.

use strict; use warnings; my @test = ( qw / bing bong bang / ); print '['.$test[2].'] ['.$test[1].'] ['.$test[0]."]\n"; my %bits; $bits{'one'}= \@test; my $new = $bits{'one'}; #new holds the array ref, not a copy of the e +ntire array print '['.$new->[2].'] ['.$new->[1].'] ['.$new->[0]."]\n";#to get elem +ents from array ref, use -> operator

In reply to Re: A hash of lists by pg
in thread A hash of lists by wolis

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.