Hi -
> -----Original Message-----
> From: R. Joseph Newton [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, February 09, 2003 3:32 PM
> To: Troy May
> Cc: Perl List
> Subject: Re: Removing duplicates from an array
>
>
> 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.
>
Yes prevention is prob the best way.
But if you must remove dups anyway:
...@array_with_dups in the input array...
my %temp_hash;
$temp_hash{$_} = 1 for (@array_with_dups);
my $array_without_dups = ();
push @array_without_dups, $_ for (keys %temp_hash);
The downside is that thr array order will be messed up...
You can sort it: ... for (sort keys ...
Aloha => Beau;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]