johnirl has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/perl use strict; my @array1 = (0,1,2,3,4,5,6,7,8,9); my @array2 = (0,1,4,); my $num = "3"; my $array1size = @array1; my $array2size = @array2; for (my $count1=0;$count1 < $array1size;$count1++){ for (my $count2=0;$count2 < $array2size;$count2++){ if ($array1[$count1] == $array2[$count2]){ print $array1[$count1] . " is present in array1 and it (" . $a +rray2[$count2] . ") is also present in array2!\n"; splice (@array1, $count1, 1); splice (@array2, $count2, 1); } } }
Any idea why this isn't working. My expected output is
O is present in array1 and it(0) is also present in array2! 1 is present in array1 and it(1) is also present in array2! 4 is present in array1 and it(4) is also present in array2!
Thanks
j o h n i r l .
Sum day soon I'Il lern how 2 spelI (nad tYpe)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing and Removing Duplicates in Arrays
by andye (Curate) on Aug 21, 2002 at 10:48 UTC | |
by jmcnamara (Monsignor) on Aug 21, 2002 at 11:04 UTC | |
by andye (Curate) on Aug 21, 2002 at 11:14 UTC | |
|
Re: Printing and Removing Duplicates in Arrays
by tommyw (Hermit) on Aug 21, 2002 at 10:38 UTC | |
|
Re: Printing and Removing Duplicates in Arrays
by thor (Priest) on Aug 21, 2002 at 12:27 UTC | |
|
Re: Printing and Removing Duplicates in Arrays
by Basilides (Friar) on Aug 21, 2002 at 12:38 UTC |