# build a hash that contains only excluded IDs
my %exclude = map { ( $_->{id} => 1 ) } @AoH_one;
# now keep only those that are not excluded:
my @keepers = grep { not $exclude{ $_->{id} } } @AoH_all;
####
@AoH_all = grep { not $exclude{ $_->{id} } } @AoH_all;
####
# use liz's technique
foreach my $i ( reverse 0 .. $#AoH_all )
{
if ( $exclude{ $AoH_all[$i]{id} } )
{
splice @AoH_all, $i, 1;
}
}
# keep track of things manually
my $n_elt = @AoH_all;
for ( my $i = 0; $i < $n_elt; ++$i )
{
if ( $exclude{ $AoH_all[$i]{id} } )
{
splice @AoH_all, $i, 1;
--$n_elt;
# whoops, bug here, see update...
}
}
# finally, perl updates the length of @AoH_all for us, so:
for ( my $i = 0; $i < @AoH_all; ++$i )
{
if ( $exclude{ $AoH_all[$i]{id} } )
{
splice @AoH_all, $i, 1;
# whoops, bug here, see update...
}
}
####
# adjust $i after replacement so it is reexamined:
for ( my $i = 0; $i < @AoH_all; ++$i )
{
if ( $exclude{ $AoH_all[$i]{id} } )
{
splice @AoH_all, $i, 1;
--$i;
}
}
# or, only increment $i if we didn't do a replacement:
for ( my $i = 0; $i < @AoH_all; )
{
if ( $exclude{ $AoH_all[$i]{id} } )
{
splice @AoH_all, $i, 1;
}
else
{
++$i;
}
}