Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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 (Bishop) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-02-25 04:17 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.