Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How do I find if an array has duplicate elements, if so discard it?

by DamnDirtyApe (Curate)
on Jul 13, 2002 at 22:12 UTC ( [id://181536]=note: print w/replies, xml ) Need Help??


in reply to How do I find if an array has duplicate elements, if so discard it?

use strict ; use warnings ; use Data::Dumper ; sub has_dups { my $arr = shift ; my %counter ; foreach ( @$arr ) { return 1 if $counter{$_}++ ; } return 0 ; } my @A = (1, 2, 3, 4, 5) ; my @B = (6, 7, 7, 8, 9) ; my @C = (10, 11, 12, 13, 15) ; my @D = grep { !has_dups($_) } ( \@A, \@B, \@C ) ; print Dumper( \@D ) ;
  • Comment on Re: How do I find if an array has duplicate elements, if so discard it?
  • Download Code

Replies are listed 'Best First'.
Re: Answer: Clarify: How do I find if an array has duplicate elements, if so discard it?
by ysth (Canon) on Nov 07, 2003 at 10:11 UTC
    I took a look at this and wondered what on earth it was trying to do. Then I reread the question. This answer does try to provide a meaningful example of detecting an array with duplicate elements and discarding it. But I have a feeling the questioner meant to say "if so discard" them.

    If you are downvoting this for other than lack of interest, thanks for sending me a message or reply to let me know why so I can do better (or just stay quiet) next time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181536]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found