in reply to Return a Unique Array

Trying again with HTML tags... You can achieve the same effect by creating hash keys (they must be unique) then assigning the keys to an array. Ie:
<<<<<<<<<<<<<<<<<

my ($char,%hash) ;

my (@nonuniquearray) = (a,a,b,c,c,d,e,f) ;

for $char (@nonuniquearray) {

        $hash{$char} =1 ;
}

my (@uniquearray) = keys(%hash) ;

>>>>>>>>>>>>>>>>>>>
- James

Replies are listed 'Best First'.
RE: RE: Return a Unique Array
by Anonymous Monk on Feb 19, 2000 at 20:58 UTC
    I like to use:
    for (@array) { $foo{$_}++ }; @unique = (keys %foo);
    ...which also allows me to count occurances of different values:
    $applecount = %foo{'apple'};