in reply to Re: Data::Rmap to modify an arrayref of arrayrefs
in thread Data::Rmap to modify an arrayref of arrayrefs

That is not the target structure specified in the OP:
[ 'note', [ 'shopping', [ item => 'bread' ], [ item => 'butter' ], [ item => 'beans' ], ] ];




The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- 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 GrandFather (Saint) on Jul 02, 2011 at 22:11 UTC

    The structure may not be right, but the sense is and I see your solution takes elements from my code so it wasn't all loss was it? You may find the following trivial variant more to your liking:

    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); $_ = ['shopping', @item]; Data::Rmap::cut ($_); } $initial; print Data::Dump::dump ($initial), "\n";

    prints:

    [ "note", [ "shopping", ["item", "bread"], ["item", "butter"], ["item", "beans"], ], ]
    True laziness is hard work