Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Remove duplicates

by perlnoobster (Sexton)
on Nov 15, 2012 at 09:17 UTC ( [id://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

Replies are listed 'Best First'.
Re: Remove duplicates
by marto (Cardinal) on Nov 15, 2012 at 09:20 UTC
Re: Remove duplicates
by choroba (Cardinal) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found