Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Remove duplicates

by perlnoobster (Sexton)
on Nov 15, 2012 at 09:17 UTC ( #1003972=perlquestion: print w/replies, xml ) Need Help??
perlnoobster has asked for the wisdom of the Perl Monks concerning the following question:

Hi perl monks, I'm attempting to remove duplicates:
my (@Category_Link)=$main_page=~m!<a href=" +tm/(.+?)"!sg; for my $temp_page (@Category_Link) { my @uniq = grep $temp_page{$_}++, @Category_Link; print OUT "$temp_page\n"; }
I am fairly new to perl and learning slowly but surely, but can't figure it out please can someone help? Thank you

Replies are listed 'Best First'.
Re: Remove duplicates
by marto (Bishop) on Nov 15, 2012 at 09:20 UTC
Re: Remove duplicates
by choroba (Chancellor) on Nov 15, 2012 at 09:21 UTC
    Use strict. $temp_page is different from %temp_page.

    You can use uniq from List::MoreUtils. Or, make your own:

    sub uniq { my %tmp; undef @tmp{@_}; return keys %tmp; } my (@Category_Link) = uniq($main_page =~ m!<a href=" +)"!sg);
    Update: Usage line added.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Remove duplicates
by Anonymous Monk on Nov 15, 2012 at 09:23 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1003972]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2016-10-26 06:49 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (336 votes). Check out past polls.