But that's not what uniq does: it only removes elements that are the same as the previous element in the list.Are you looking at a different version of perlfaq4? My perl 5.8.6 version of perlfaq 4 "How can I remove duplicate elements from a list or array" gives 5 options, option a) of which states:
If @in is sorted, and you want @out to be sorted: (this assumes all true values in the array)This is nice in that it doesn't use much extra memory, simulating uniq(1)'s behavior of removing only adjacent duplicates. The ``, 1'' guarantees that the expression is true (so that grep picks it up) even if the $_ is 0, ``'', or undef.$prev = "not equal to $in[0]"; @out = grep($_ ne $prev && ($prev = $_, 1), @in);
In reply to Re^3: Finding unique elements in an array
by eyepopslikeamosquito
in thread Finding unique elements in an array
by Eyck
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |