[EMAIL PROTECTED] wrote:
> I need to test if an array holds duplicates, and if so do something.
If you just need to check for the presence of a duplicate, something like
this will do the trick:
sub has_dup { my %seen; $seen{$_}++ && return 1 for @_; }
Of course, all the hash-based methods depe
On Apr 20, [EMAIL PROTECTED] said:
>I need to test if an array holds duplicates, and if so do something.
>
>What is the slickest way of doing this ?
The documentation offers a couple ways; the most common idiom uses a hash,
as other people have shown.
However, you can leave the hard work to Perl
<[EMAIL PROTECTED]> asked:
> I need to test if an array holds duplicates, and if so do something.
Try
use strict;
use warnings;
my @array = qw(foo baz bar foo);
my %have;
foreach my $item (@array){
warn "duplicate item $item" if exists $have{$i