as numbers are selected
remove elements from array A
repopulate list with what is remaining into array A
print array A
####
#!/usr/bin/perl -w
use strict;
use Dumpvalue;
my $d = new Dumpvalue;
#testing
my @ArrayA = (0 .. 100);
print "before\n";
$d->dumpValues(\@ArrayA);
print "\n";
#more testing.
my @numbers_to_remove = (14 .. 36, 50 .. 63, 89, 91, 94);
#here we reassign @ArrayA with the return value from
#our do{} block.
@ArrayA = do {
#make a local copy of @ArrayA as is to begin with
my @tmp = @ArrayA;
#map returns a list which comes in handy here
map{
#make a local copy of the incoming elements from
#our local copy in @tmp
my $key = $_;
#use a ternary operator to make sure we are
#not including numbers from our
#@numbers_to_remove list. If it is not
#found return it otherwise return an
#empty list.
(!grep /^$key$/, @numbers_to_remove) ? $key : ();
}@tmp; #for each element in @tmp
};
print "After\n";
$d->dumpValues(\@ArrayA);
print "\n";
##
##
use Dumpvalue;
my $d = new Dumpvalue;
#create the hypothetical structure. An array of
#hash references each with an id field in it.
my @ArrayB = map{{id=>$_}}(0 .. 100);
$d->dumpValues(\@ArrayB);
print "\n";
#more testing.
#these would correspond to id's to remove in our hypothetical
#scenario.
my @ids_to_remove = (14 .. 36, 50 .. 63, 89, 91, 94);
@ArrayB = do{
my @tmp = @ArrayB;
map{
my $key = $_->{id};
(!grep /^$key$/, @ids_to_remove) ? $_ : () ;
}@tmp;
};
$d->dumpValues(\@ArrayB);
exit;