The stupid question is the question not asked PerlMonks

### Re: How do I remove the duplicates from the array?

 on Sep 25, 2013 at 22:55 UTC ( #1055755=note: print w/replies, xml ) Need Help??

This one assumes integer values:

```use strict;
use warnings;

# Including choroba's sevens.
my @array  = qw(-20 20 1 1 2 2 2 9 3 -4 -4 5 -20 20 7 7 7);
my @array1 = qw( 10 11 7 9 3 3 3 1 3  4  5 5   1 30 8 7 8);

# Tuple of array elements as "key"/"val" pairs.
my @pairs;

# Max "val" for each "key".
my %max;

for (0..\$#array) {
my \$key = \$array[\$_];
my \$val = \$array1[\$_];
my \$max = \$max{\$key};

push @pairs, [\$key, \$val];

if (defined \$max) {
next if \$val < \$max;

# For the "2"/"3" pairs.  Only want "highlander" max, so
# increase by a fraction (assumes integers in @array1).
\$val += 0.5 if \$val == \$max;
}

\$max{\$key} = \$val;
}

my (@output, @output1);

for (@pairs) {
my (\$key, \$val) = @\$_;
next unless \$val == \$max{\$key};
push @output, \$key;
push @output1, \$val;
}

say join ',', map sprintf('%3d', \$_), @\$_
for \@output, \@output1;

__END__
-20,  1,  9,  3, -4,  5, 20
10,  9,  1,  3,  5,  5, 30

Replies are listed 'Best First'.
Re^2: How do I remove the duplicates from the array?
by PetreAdi (Acolyte) on Sep 26, 2013 at 08:54 UTC

Very good

Thank you

Create A New User
Node Status?
node history
Node Type: note [id://1055755]
help
Chatterbox?
 [choroba]: marto I don't know them, but their fb page has a black avatar and background... [marto]: #deletefacebook

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-03-22 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (273 votes). Check out past polls.

Notices?