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 = newnode($initial_lol, item => shopping_items()); warn Dumper($new_lol); sub newnode { my ($lol, $node_label, $new_node)=@_; my ($mapresult) = rmap_array { if ($_->[0] eq $node_label) { $_ = shopping_items(); 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^3: Data::Rmap to modify an arrayref of arrayrefs
by metaperl
in thread Data::Rmap to modify an arrayref of arrayrefs
by metaperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |