in reply to Is there better way to delete dups in an AoH?
my @allvalues; for my $i ( 0 .. $#AoH ) { push ( @allvalues, $AoH[$i]{ page } ); }
In general, building up an array by pushing in a loop can usually be done more elegantly with map/grep:
my @allvalues = map $_->{page}, @AoH;
However, if the only purpose for this array is to locate the duplicates for deletion, you don't really need this array or the duplicates array:
# count occurrences of each value my %count; ++$count{$_->{page}} for @AoH; # keep only those copies that aren't duplicated @AoH = grep $count{$_->{page}} == 1, @AoH;
That is:
# replace @AoH with @AoH = # only grep # the hashrefs whose 'page' value appears exactly once $count{$_->{page}} == 1, # of the current @AoH @AoH;
Hugo
|
|---|