in reply to Data::Rmap to modify an arrayref of arrayrefs
The trick seems to be to replace the 'items' sub-element:
use strict; use warnings; use Data::Dump qw(); use Data::Rmap qw(); my $initial = [note => [shopping => ['item']]]; Data::Rmap::rmap_array { return $_ if $_->[0] ne 'shopping'; # Ignore non-shopping entries my @item= map {[item => $_]} qw(bread butter beans); $_->[1] = ['shopping', @item]; Data::Rmap::cut ($_); } $initial; print Data::Dump::dump ($initial), "\n";
Prints:
[ "note", [ "shopping", [ "shopping", ["item", "bread"], ["item", "butter"], ["item", "beans"], ], ], ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Data::Rmap to modify an arrayref of arrayrefs
by metaperl (Curate) on Jul 02, 2011 at 10:23 UTC | |
by GrandFather (Saint) on Jul 02, 2011 at 22:11 UTC |