I haven't used Data::Rmap before so others may have better answers. However, the following works and solves your problem.
use strict; use warnings; use Data::Rmap qw(:all); my $initial = [ note => [ shopping => [ 'item' ] ] ]; use Data::Dumper; # build a list of shopping items ** for reuse ** my @shopping_items; for my $item qw(bread butter beans) { push @shopping_items, [ item => $item ]; } my ($dump) = rmap_array { # If we get an arrayref whose first element is 'shopping' if ($_->[0] eq 'shopping') { # Make the second element the shopping list $_->[1] = [ @shopping_items ]; # No need to drill down any further cut($_); } else { # if the arrayrefs first element is not 'shopping' # then simply pass it through $_; } } $initial; warn Dumper($initial, $dump);
-- Ken
In reply to Re: Data::Rmap to modify an arrayref of arrayrefs
by kcott
in thread Data::Rmap to modify an arrayref of arrayrefs
by metaperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |