in reply to finding the distinct elements in an array
While it's a fairly common idiom to produce, and the usual manner is to use a hash to filter uniques, it's less error-prone to simply use the common module, List::MoreUtils, with its uniq() method.
use strict; use warnings; use List::MoreUtils qw( uniq ); my @array = (1, 1, 3, 2, 8, 9, 4, 2, 3); print uniq( @array ), "\n";
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: finding the distinct elements in an array
by jdtoronto (Prior) on May 29, 2006 at 16:21 UTC |