in reply to Re: Data::Rmap to modify an arrayref of arrayrefs
in thread Data::Rmap to modify an arrayref of arrayrefs
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"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Data::Rmap to modify an arrayref of arrayrefs
by metaperl (Curate) on Jul 03, 2011 at 00:31 UTC | |
by metaperl (Curate) on Jul 08, 2011 at 20:49 UTC |