develooper Front page | perl.perl5.porters | Postings from February 2000

[DOCPATCH 5.5.650] perlfunc/each

Thread Previous | Thread Next
February 18, 2000 08:19
[DOCPATCH 5.5.650] perlfunc/each
Message ID:
crypt% perl -we '%a = (0, 0, 1, 1); while (($k, $v) = each %a) { print "$k $v\n" }'
0 0
1 1
crypt% perl -we '%a = (0, 0, 1, 1); while ($k = each %a) { print "$k\n" }'

I'm not entirely sure that I understand why the second one works, but
the docs imply it shouldn't. Am I missing something here?

--- pod/perlfunc.pod.old	Mon Feb  7 07:04:17 2000
+++ pod/perlfunc.pod	Fri Feb 18 16:23:14 2000
@@ -1153,9 +1153,7 @@
 When called in list context, returns a 2-element list consisting of the
 key and value for the next element of a hash, so that you can iterate over
 it.  When called in scalar context, returns the key for only the "next"
-element in the hash.  (Note: Keys may be C<"0"> or C<"">, which are logically
-false; you may wish to avoid constructs like C<while ($k = each %foo) {}>
-for this reason.)
+element in the hash.
 Entries are returned in an apparently random order.  The actual random
 order is subject to change in future versions of perl, but it is guaranteed

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About