I have two arrays like this...
I want to find out which elements in @a2 are NOT in @a1. I've tried using both grep and exists but couldn't get either one working right.
@new should be equal to (2, 4, 6).
fyi, this all has to do with the other thread I started earlier today titled "comparing arrays".
Thanks,
Chris
Code:
@a1 = qw/1 3 5 7 9 11 13/;
@a2 = qw/1 2 3 4 5 6 7/;
I want to find out which elements in @a2 are NOT in @a1. I've tried using both grep and exists but couldn't get either one working right.
Code:
foreach $a2 (@a2) {
@new = grep (!/$a2/, @a1);
}
print "@new\n";
@new should be equal to (2, 4, 6).
fyi, this all has to do with the other thread I started earlier today titled "comparing arrays".
Thanks,
Chris