I have a process which is gathering links from a webpage for later conversion/processing, and I want to push unique links onto an array, so I can process them later.
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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.