in reply to finding unique elements in an array
It probably can be done shorter, but I think this code conveys the idea quite clearly.my %array_count; foreach my $elem (@array) { $array_count{$elem}++; } foreach my $key (keys %array_count) { print "$key\n" if $array_count{$key} == 1; }
The elements of the array become the keys of the hash, and the values of the hash are the number of times that the element is present in the array.
Arjen
|
|---|