Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find the element which are duplicated in an array

Posted on 2011-09-30
3
Medium Priority
?
254 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 85

Expert Comment

by:ozo
ID: 36890344
have you read
perldoc -q duplicate
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 2000 total points
ID: 36892831
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
ID: 36935026
Thank you! :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

879 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