johnirl has asked for the wisdom of the Perl Monks concerning the following question:
Hey Monks
For some reason I am unable to wrap my head around this problem today. What I need to do is locate all elements in array 1 that are not in array2.
For some reason I am unable to wrap my head around this problem today. What I need to do is locate all elements in array 1 that are not in array2.
@array1 = ("q", "w", "e", "r", "t", "z"); @array2 = ("q", "w", "e", "r", "t", "y"); OUTPUT: ------- Value z does not match any value in @array2
My Effort
Thanks to all in advance.my $array1_size = scalar(@array1); my $array2_size = scalar(@array2); for(my $i = $array1_size; $i > 0 ; $i--) { for (my $j = $array2_size; $j > 0 ; $j--) { if ($array1[$i] eq $array2[$j]){ pop @array1; pop @array2; $j--; $i--; $array1_size--; $array2_size--; } } }
Ever have one of those days?
j
o
h
n
i
r
l
.
Sum day soon I'Il lern how 2 spelI (nad tYpe)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing Two arrays
by davorg (Chancellor) on Sep 19, 2002 at 16:05 UTC | |
Re: Comparing Two arrays
by Zaxo (Archbishop) on Sep 19, 2002 at 15:56 UTC | |
by sauoq (Abbot) on Sep 19, 2002 at 18:49 UTC | |
Re: Comparing Two arrays
by fruiture (Curate) on Sep 19, 2002 at 15:57 UTC | |
•Re: Comparing Two arrays
by merlyn (Sage) on Sep 19, 2002 at 15:57 UTC | |
by johnirl (Monk) on Sep 19, 2002 at 16:04 UTC | |
Re: Comparing Two arrays
by RollyGuy (Chaplain) on Sep 19, 2002 at 16:00 UTC | |
Re: Comparing Two arrays
by nandeya (Monk) on Sep 19, 2002 at 18:45 UTC | |
Re: Comparing Two arrays
by Joost (Canon) on Sep 20, 2002 at 10:57 UTC |
Back to
Seekers of Perl Wisdom