The_Rev has asked for the wisdom of the Perl Monks concerning the following question:
I've written the following code snippet to try and demonstrate my problem:
I need to compare the two arrays (one being an array of arrays), against another array, more specifically look at the second element of @array against the contents of @compare and eliminate the duplicates from @array.#!/perl/bin/perl.exe -w use strict; use vars qw(@array @data @compare $num ); $num = 0; for (0 .. 3) { @array = (); for (0 .. 1) { push @array, $num; $num ++; } push @data, [@array]; } @compare = (2, 4, 5, 6); print "Contents of \@array\n"; foreach my $record (@data) { for my $i (0 .. 1) { print $record->[$i] . " "; } print "\n"; } print "\n\nContents of \@compare\n"; foreach (@compare) { print $_, " "; }
I should end up with the following values for @array ...
Notice that the number 5 was the second element in @array Any ideas ?Contents of @array 0 1 2 3 6 7 Contents of @compare 2 4 5 6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array element removal
by sauoq (Abbot) on Dec 17, 2002 at 23:27 UTC | |
|
Re: Array element removal
by BrowserUk (Patriarch) on Dec 17, 2002 at 23:31 UTC | |
|
Re: Array element removal
by jdporter (Paladin) on Dec 17, 2002 at 23:07 UTC | |
by jdporter (Paladin) on Dec 17, 2002 at 23:12 UTC | |
by sauoq (Abbot) on Dec 17, 2002 at 23:34 UTC | |
by BrowserUk (Patriarch) on Dec 17, 2002 at 23:46 UTC | |
by The_Rev (Acolyte) on Dec 17, 2002 at 23:19 UTC |