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

I had to do some ugly in-place modification:
use strict; use warnings; use Data::Rmap qw(:all); my $initial = [ note => [ shopping => [ 'item' ] ] ]; use Storable qw(dclone); my $clone = dclone $initial; use Data::Dumper; my ($dump) = rmap_all { if (ref and $_->[0] eq 'shopping') { my @item = map { [ item => $_ ] } qw(bread butter beans); warn Dumper(\@item); my $newdata = [ shopping => \@item ]; $_ = $newdata; } else { $_ = $_; } } $clone ; warn Dumper($initial, $dump);




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^2: Data::Rmap to modify an arrayref of arrayrefs
by GrandFather (Saint) on Jul 02, 2011 at 22:23 UTC

    Why:

    } else { $_ = $_;

    which does nothing, and why:

    my $newdata = [ shopping => \@item ]; $_ = $newdata;

    when you could just:

    $_ = [ shopping => \@item ];

    or maybe even:

    $_ = [shopping => [map {[item => $_]} qw(bread butter beans)]];

    for the whole if block.

    True laziness is hard work