Do you want to keep the duplicate elements simply and don't mind the order of 
them?
If I have understood for you correctly,I should write the code as below:

use strict;
use warnings;

my @array = qw/aaa bbb ccc aaa ddd ddd aaa ccc bbb bbb/;
my %hash;
$hash{$_}++ for @array;
my @duplicate = grep { $hash{$_} == 2 } keys %hash;
print join ' ',@duplicate;


-----Original Message-----
>From: anand kumar <[EMAIL PROTECTED]>
>Sent: Feb 6, 2006 2:34 AM
>To: beginners@perl.org
>Subject: Duplicates elements in an array
>
>Hi all
>   
>             I have an array with hundreads of elements in it. Can anyone 
> suggest the easiest way to keep only the duplicate elements in the array.
>   
>  Thanks in Advance for the help
>   
>  Regards
>  Anand
>
>                               
>---------------------------------
> Jiyo cricket on Yahoo! India cricket


--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to