Solved

Find the element which are duplicated in an array

Posted on 2011-09-30
3
208 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
ID: 36890344
have you read
perldoc -q duplicate
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Script - Remove row of data based on column value 3 74
rename outfile before writing 2 71
Migrate OTRS to newest version. 1 309
add a syntax to a csv file 8 98
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

14 Experts available now in Live!

Get 1:1 Help Now