Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:
I am pulling my hair out trying to figure out why the following snippit:
Produces this (what I want):foreach my $i (@{$t}) { my $id = $i->{id}; my $subs = $i->{subs}; my $name = $i->{name}; my $rv = $sth->execute($id); while (my $r = $sth->fetchrow_hashref) { $r->{cat} = ( { name=>$name,id=>$id } ); push (@{$p},$r); } return($p); }
But this snippit:$VAR1 = [ { 'cat' => { 'name' => 'Category', 'id' => '2558' }, 'name' => 'Product One', 'id' => '7669' }, { 'cat' => { 'name' => 'Category', 'id' => '2558' }, 'name' => 'Product Two', 'id' => '7670' }, ];
Produces this:foreach my $i (@{$t}) { my $id = $i->{id}; my $subs = $i->{subs}; my $name = $i->{name}; my $rv = $sth->execute($id); my $cat = ( { name => $name, id => $id } ); while (my $r = $sth->fetchrow_hashref) { $r->{cat} = $cat; push (@{$p},$r); } return($p); }
Any enlightenment would be greatly appreciated!$VAR1 = [ { 'cat' => { 'name' => 'Category', 'id' => '2558' }, 'name' => 'Product One', 'id' => '7669' }, { 'cat' => $VAR1->[0]{'cat'}, 'name' => 'Product Two', 'id' => '7670' }, ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange hash array behavior
by ikegami (Patriarch) on Jan 29, 2009 at 00:12 UTC | |
by Rodster001 (Pilgrim) on Jan 29, 2009 at 03:25 UTC | |
by Util (Priest) on Jan 29, 2009 at 05:02 UTC | |
by Rodster001 (Pilgrim) on Jan 29, 2009 at 05:19 UTC | |
by ikegami (Patriarch) on Jan 29, 2009 at 15:26 UTC | |
by ig (Vicar) on Jan 29, 2009 at 05:53 UTC | |
| |
by Util (Priest) on Jan 29, 2009 at 06:27 UTC |