summaryrefslogtreecommitdiff
path: root/pod/perlfaq4.pod
diff options
context:
space:
mode:
authorHans Ginzel <hans@kolej.mff.cuni.cz>2000-10-27 21:28:30 +0200
committerJarkko Hietaniemi <jhi@iki.fi>2000-10-28 19:13:06 +0000
commit3bc5ef3eb693992b74dc57b15c2a80e4e456a97e (patch)
treec4e31ba3c30c942c391e0f31533c29b5a87b3baf /pod/perlfaq4.pod
parentfcae944a9e9281b32a3f7123ffca88faf583908e (diff)
downloadperl-3bc5ef3eb693992b74dc57b15c2a80e4e456a97e.tar.gz
[ID 20001027.007] uniq array in perlfaq
Message-Id: <20001027192830.A1564@kolej.mff.cuni.cz> p4raw-id: //depot/perl@7474
Diffstat (limited to 'pod/perlfaq4.pod')
-rw-r--r--pod/perlfaq4.pod8
1 files changed, 4 insertions, 4 deletions
diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
index 79905f88ce..9d6b766a9f 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: