Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 (Chancellor) on Nov 15, 2012 at 09:20 UTC
Re: Remove duplicates
by choroba (Abbot) 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 chilling in the Monastery: (20)
As of 2014-08-29 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (281 votes), past polls