in reply to Re: Two arrays. One hash.
in thread Two arrays. One hash.
And the output -use strict; my @keyset = qw/this repeat that repeat/; my @valset = qw/jerry george elaine kramer/; print "\@keyset has ", hasdup(\@keyset) ? "duplicates (warning)" : "no duplicates", "\n"; print "\@valset has ", hasdup(\@valset) ? "duplicates" : "no duplicates", "\n"; sub hasdup { my $array = shift; # get the index of the elements in the uniq array my $last = $#{[keys %{{ map {$_ => 1} @$array }}]}; return $#{@$array} != $last; }
@keyset has duplicates (warning) @valset has no duplicates
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
3Re: Two arrays. One hash.
by jeffa (Bishop) on Nov 30, 2003 at 15:46 UTC |