Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
If I grab slashdot.org, for example and extract the links from it, it will link to freshmeat.net. If I then grab freshmeat.net, and grab the links from it, there is a link (back) to slashdot.org. I would like to push the unique links found onto an array I can then manipulate later.
I know I can compute the intersection of two arrays using code similar to the snippet below, but how do I check at push() time, if the element I'm going to be pushing onto the array, is in fact unique, before I push it on?
my @fruit = ('apple', 'pear', 'lemon', 'celery', 'pear'); my %seen = (); foreach (@fruit) { $seen{$_}=1; } my @unique = keys %seen;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pushing unique items onto an array
by sauoq (Abbot) on May 30, 2003 at 17:05 UTC | |
by Anonymous Monk on May 30, 2003 at 17:16 UTC | |
by sauoq (Abbot) on May 30, 2003 at 17:27 UTC | |
by sauoq (Abbot) on May 30, 2003 at 17:43 UTC | |
|
Re: Pushing unique items onto an array
by cciulla (Friar) on May 30, 2003 at 17:09 UTC | |
|
Re: Pushing unique items onto an array
by DrManhattan (Chaplain) on May 30, 2003 at 17:09 UTC | |
|
Re: Pushing unique items onto an array
by Cody Pendant (Prior) on May 31, 2003 at 00:16 UTC | |
|
Re: Pushing unique items onto an array
by Limbic~Region (Chancellor) on May 31, 2003 at 01:04 UTC |