Troy May wrote:

> Hello,
>
> What's the best and cleanest way to remove duplicates from an array?  I have
> an array that reads entries from a text file and I would like to remove all
> the duplicates from it.
>
> Thanks in advance!
>
> Troy

I'd say prevention is the best cure.  Check for duplicates as you read.

You need to prevent duplication raises another question, though.  Is an array really 
the best data structure for your purpose.  The hash structure was created to maintain 
uniqueness of keys.  Therefore, if you store your elements as hash keys, then you 
could be assured that there is no duplication:
if ( defined( $contents{$currentKey} ) ) {contents{$currentKey}++;}
else {$contents{$currentKey} = 1;}

Joseph




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

Reply via email to