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' }, ];
In reply to Strange hash array behavior by Rodster001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |