perl: remove elements of array2 from array1
Name:
Anonymous
2010-05-14 6:41
Hi, I'm learning perl programming and would appreciate some help. How do I write code to remove elements of array2 from array1
I.e.
@array1={'a','b','c','d'}
@array2={''a','z','c','x'}
(magic happens, processes @array1 and @array2)
dump @array1 gives 'b','d'
Any clues?
Thanks!
Name:
Anonymous
2010-05-14 6:45
nevermind, found something
@array1=(1,2,4,6,7,8);
@array2=(1,2,3,5,6,7);
for $i (@array1) {
print "$i\n" if ! grep {$i == $_} @array2;
}
Name:
Anonymous
2010-05-14 8:17
>>1
I have discovered your problem:
I'm learning perl programming
Name:
Anonymous
2010-05-14 9:48
>>3
Expert in depth analysis.
Name:
Anonymous
2010-05-14 13:21
>>> array1 = {'a', 'b', 'c', 'd'}
>>> array2 = {'a', 'z', 'c', 'x'}
>>> array1 -= array2
>>> array1
{'b', 'd'}
Name:
Anonymous
2010-05-14 13:33
>>5
Wait, you can do that? What's the big-Oh for that?
Name:
Anonymous
2010-05-14 13:36
>>6
girlsAll-GirlsWithBoyFriends
Name:
Anonymous
2010-05-14 13:49
>>6
It's constant time, like all interpreted languages.