in reply to Basic help with mapping
If you do want to make a copy, then you should really make it a deep copy because otherwise your two arrays will really be identical, since they have the same references in them. For this you can use map:for (@$AoH_orig) { $_->{title} =~ s/-/_/g; }
The key points here are a) I am calling map in list context and returning the result as an array reference, since that's what you want $AoH_new to be (otherwise you'd have to make it a real array like @AoH_new) and b) I need to actually copy the hash for each element in order to make a completely new structure.my $AoH_new = [ map { my %tmp = %$_; $tmp{title} =~ s/-/_/g; \%tmp } @ +$AoH_orig ];
|
|---|