I have an array which contains several strings. There is another array which contains strings which may or may not be contained in the first array.
What is the best way to remove any instances of a string in array b from the strings in array a. I have tried to use grep as in the example below but it completely empties the array.
my @Aray = ('Chris', 'John', 'Paul', 'Max', 'Jim', 'John');
my @Bray = ('Chris', 'John');
foreach $name (@Bray){
@Aray = grep {$_ != $name} @Aray;
}
This would result in no elements left in @Aray, opposed to 'Paul', 'Max', 'Jim'
I also tried with a traditional for loop and indexing each name in @Bray with the same result.
neinstead of!=for strings.use warnings;perl -E"use warnings; say 'a' != 'b' ? 'not equal' : 'equal'"toperl -E"say 'a' != 'b' ? 'not equal' : 'equal'"