in reply to A hash of lists
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
|
|---|