in reply to Help with array ref in hashes

I, too, seem to be getting the output I think you want to get from the OPed code (with missing  $ sigil restored):

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $line = 'foo'; my @data = qw(hi ha ho); my @site = (9, 8, 7); my %lengths; ;; $lengths{$line} = { x => $site[0], y => $site[1], z => \@data }; dd \%lengths; ;; for my $coord (keys %lengths) { for (@{$lengths{$coord}{z}}) { print $_; } } " { foo => { x => 9, y => 8, z => ["hi", "ha", "ho"] } } hi ha ho


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^2: Help with array ref in hashes
by diyaz (Beadle) on Jan 12, 2015 at 15:28 UTC
    ok thanks to everyone for your help. i just realized i made a dumb mistake that I was passing the reference \@data to z but since it is a temporary variable I was using to pass data I was erasing it everytime. I guess I need to for loop the storage of @data into my hash.