Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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="http://www.testsite.co.uk/i +tm/(.+?)"!sg; for my $temp_page (@Category_Link) { my @uniq = grep $temp_page{$_}++, @Category_Link; print OUT "http://www.testsite.co.uk/itm/$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

Comment on Remove duplicates
Download Code
Re: Remove duplicates
by marto (Bishop) on Nov 15, 2012 at 09:20 UTC
Re: Remove duplicates
by choroba (Canon) 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="http://www.testsite.co.uk/itm/(.+? +)"!sg);
    Update: Usage line added.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Remove duplicates
by Anonymous Monk on Nov 15, 2012 at 09:23 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-04 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls