From: Hans Ginzel Date: Fri, 27 Oct 2000 19:28:30 +0000 (+0200) Subject: [ID 20001027.007] uniq array in perlfaq X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3bc5ef3eb693992b74dc57b15c2a80e4e456a97e;p=p5sagit%2Fp5-mst-13.2.git [ID 20001027.007] uniq array in perlfaq Message-Id: <20001027192830.A1564@kolej.mff.cuni.cz> p4raw-id: //depot/perl@7474 --- diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index 79905f8..9d6b766 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -952,12 +952,12 @@ ordered and whether you wish to preserve the ordering. (this assumes all true values in the array) $prev = 'nonesuch'; - @out = grep($_ ne $prev && ($prev = $_), @in); + @out = grep($_ ne $prev && ($prev = $_, 1), @in); This is nice in that it doesn't use much extra memory, simulating -uniq(1)'s behavior of removing only adjacent duplicates. It's less -nice in that it won't work with false values like undef, 0, or ""; -"0 but true" is OK, though. +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. =item b) If you don't know whether @in is sorted: