You will never have duplicate keys in a hash.  If you try to use the same
key more than once, it will simply overwrite the previous definition:

%blah=('a_key' => 'first definition', 'a_key' => 'second definition',
'a_key' => 'YES!!')

the key 'a_key' appeared three times, but each time it overwrites the
previous definition, so in the end, %blah contains exactly one key and its
associated value:

$blah{'a_key'} eq 'YES!!'

But my guess is that you are trying to weed out duplicates in an array, not
a hash, in which case you need to do something like this:

@array=qw/one two three two one two three two four five four/;

# creates a hash using the elements from @array as keys, which eliminates
any duplicates
%hash = map {($_,'whatever')} @array;

# return the keys back to the array
@array=keys %hash;

print "$_\n" for @array;
__END__

Which outputs:
one
two
three
four
five

Although probably not in that order.

I just wanted to clarify that to make sure you're not trying something like
'%hash=@array'.

hth!

-----Original Message-----
From: Jennifer Pan [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 06, 2001 12:47 PM
To: [EMAIL PROTECTED]
Subject: get rid of the same elements in an array/hash


sorry to ask this as I saw the same question but cannot remember the
answer.

if I have a hash, how do I get rid of the elements that appear more than
once?

thank you very much

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to