use strict; use warnings; use Data::Rmap qw(:all); use Data::Dumper; my $initial_lol = [ note => [ shopping => [ item => 'sample' ] ] ]; # In $initial_lol, the new child of shopping is shopping_items my $new_lol = newchild($initial_lol, shopping => shopping_items()); warn Dumper($new_lol); sub newchild { my ($lol, $parent_arrayref_label, $new_child)=@_; my ($mapresult) = rmap_array { if ($_->[0] eq $parent_arrayref_label) { $_->[1] = $new_child; cut($_); } else { $_; } } $lol; $mapresult; } sub shopping_items { my @shopping_items; for my $item qw(bread butter beans) { push @shopping_items, [ item => $item ]; } \@shopping_items; }
-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"
In reply to Re^2: Data::Rmap to modify an arrayref of arrayrefs
by metaperl
in thread Data::Rmap to modify an arrayref of arrayrefs
by metaperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |