* Added example with List::MoreUtils::uniq()
Index: perlfaq4.pod =================================================================== --- perlfaq4.pod (revision 5912) +++ perlfaq4.pod (working copy) @@ -1195,6 +1195,16 @@ my @unique = keys %hash; +If you want to use a module, try the C<uniq> function from +C<List::MoreUtils>. In list context it returns the unique elements, +reserving their order in the list. In scalar context, it returns the +number of unique elements. + + use List::MoreUtils qw(uniq); + + my @unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 1,2,3,4,5,6,7 + my $unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 7 + You can also go through each element and skip the ones you've seen before. Use a hash to keep track. The first time the loop sees an element, that element has no key in C<%Seen>. The C<next> statement