Let’s say I have these arrays
my @new = qw/a b c d e/;
my @old = qw/a b d e f/;
and I would like to them compared, so I get 3 new arrays containing the differences
- an array with the elements that are in
@newand not in@old: c - an array with the elements that are not in
@newand in@old: f - an array with the elements that are in both
@newand@old: a b d e
I am thinking about the exists function, but that only works for hashes I suppose.
Update: I messed up the letter examples.
Here’s a function that I’ve used many, many times.
It returns references to arrays containing the elements in the first/second/both lists: