Solved

Find the element which are duplicated in an array

Posted on 2011-09-30
3
199 Views
Last Modified: 2012-05-12
Hello, I am able to get the list of unique element from an array but how to get the elements which are duplicate in an array is not coming in my find. Could someone please share perl one line to get it done please. Thanks!
0
Comment
Question by:beer9
3 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
have you read
perldoc -q duplicate
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 500 total points
Comment Utility
If you're using something like this to get unique elements (you may have it more drawn out - and also, this is from the document ozo has pointed you to):
foreach my $elem ( @array )
{
    next if $seen{ $elem }++;
    push @unique, $elem;
}

Open in new window

Then you are half there.  Just look at the %seen assoc. array and look for values greater than 1.
my @dup;
for (%seen) { push(@dup, $_) if $seen{$_} > 1; };
print "@dup\n";

Open in new window

0
 

Author Closing Comment

by:beer9
Comment Utility
Thank you! :)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now