in reply to Re: Convert arrayref to AoH
in thread Convert arrayref to AoH

If data organization can be changed, update can be made simpler and (slightly, perhaps even detectably) faster by changing update array element dereference:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "my %h = map { $_ => 0 } qw(kept notkept repaired); my $a = [ [ 'kept', '1', ], [ 'repaired', '3', ], ]; ;; dd \%h; %h = (%h, map @$_, @$a); dd \%h; " { kept => 0, notkept => 0, repaired => 0 } { kept => 1, notkept => 0, repaired => 3 }

OTOH, using a for-loop to avoid creation of intermediate temp arrays might be yet simpler and even faster, although again, whether any speed gain would be significant or even detectable is an open question:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "my %h = map { $_ => 0 } qw(kept notkept repaired); my $a = [ [ 'kept', '1', ], [ 'repaired', '3', ], ]; ;; dd \%h; $h{ $_->[0] } = $_->[1] for @$a; dd \%h; " { kept => 0, notkept => 0, repaired => 0 } { kept => 1, notkept => 0, repaired => 3 }