Fellow monasterians,
I'm a little embarrassed to be this far into monkdom and still not understanding mapping (and grepping for that matter). I'm trying to alter a specific key's value in a AoH ref. I tried mapping a simple array and no problem. But I get the feeling I'm missing something really important as I'm getting zero results with my latter expressions.
#I get this my @array = qw(aaa-aaa bbb-bbb ccc-ccc); my @newarray = map { $_ =~ s/-/_/g } @array; print Dumper(@array); my $AoH_orig = [ { 'title' => 'aaa-aaa', 'name' => 'tom' }, { 'title' => 'bbb-bbb', 'name' => 'kathy' }, { 'title' => 'ccc-ccc', 'name' => 'bill' } ]; # how i would do it "long hand" for ( 0 .. $#$AoH_orig ) { $AoH_orig->[$_]{'title'} =~ s/-/_/g; } #try mapping my $AoH_new = map { $AoH_orig->[$_]{'title'} =~ s/-/_/g } @$AoH_orig; #or my $AoH_new = map { $_->{'title'} =~ s/-/_/g } @$AoH_orig; print Dumper($AoH_orig);
Comments? or can you point me to a good tutorial? Thanks in advance.
Update: I guess I was using map when I should have just been using the good olde foreach. But, hey, I'm a lot closer to getting it with everyone's help. Thanks.
In reply to Basic help with mapping by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |