using Tie::IxHash would though.

use strict;
use Tie::IxHash;

my %seen;
tie %seen, 'Tie::IxHash';

my @array = qw(fee fi fo fum fee fee fi foo fum fogie);
@seen{@array} = 1;
my @wanted = keys %seen;

print "@wanted\n";

outputs: fee fi fo fum foo fogie

Jamie

-----Original Message-----
From: Peter Scott [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 05, 2001 6:11 PM
To: Philip Peeters; [EMAIL PROTECTED]
Subject: Re: Perl: Finding unique strings in an array


At 06:02 PM 6/5/2001 -0700, Philip Peeters wrote:
>Hi,
>
>Is there some magical way to identify unique strings within an array?
>
>
>Example:
>@array = ( "beer","water","wine","beer","wine");
>and I'd like to end up with:  beer, water, wine

{ my %temp;
   @temp{@array} = ();
   @youwant = keys %temp;
}

However, that said, 99 times out of a hundred you should have been keeping
your data in a hash to begin with and you've made a design error by putting
it in an array.  Also, the above method doesn't preserve the order.


Reply via email to