Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find duplicate array values in perl [duplicate]

Tags:

perl

Possible Duplicate:
What's the most efficient way to check for duplicates in an array of data using Perl?

How to find duplicate values in array?

This is my array:

@arr - ("one","two","one","three","two");

Output will be:

one
two

Code:

while (<RFH>) {
    chomp;
    @arr = split(/\|/,$_);
    push(@arr1,$arr[4]."\n");
}
like image 427
BHARANIKUMAR.B.S SRINIVASAN Avatar asked Dec 28 '22 12:12

BHARANIKUMAR.B.S SRINIVASAN


1 Answers

One pass solution:

my %seen = ();
@dup = map { 1==$seen{$_}++ ? $_ : () } @list;
like image 129
mob Avatar answered Jan 10 '23 21:01

mob