On Wednesday 21 April 2004 09:24 am, you wrote:
> I'd like to remove duplicate values from an array to leave it with only
> unique values.  For instance, if an array contains (1,2,3,1,4,2,5) as
> values, I'd like to clean out the extra 1 and 2 to leave the values as
> (1,2,3,4,5).  Does perl have an array command to do that, or must the
> process be purely manual?

A quick solution wolud be to dump the values of the array into hash keys with 
a value of 1 or if you interested in how many times the duplicate you can 
turn the value into a counter.if the array does not need to be in any 
particular order.

my %myhash;
foreach my $item ( @myarray ){
        $myhash{ $item } = 1
        #$myhash{ $item }++   count of how many times the elements was encountered.
}
my @newarray;
foreach my $item ( keys %myhash );
        push  (@newarray, $item);
}

Not tested.

not so elegent but it works :)

if i new what you where doing with the data and what the data looked like it 
woulld be easier to suggest ideas.

HTH,
Paul Kraus


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to