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

[DOCPATCH 5.5.650] perlfunc/each

Thread Previous | Thread Next
From:
Hugo
Date:
February 18, 2000 08:19
Subject:
[DOCPATCH 5.5.650] perlfunc/each
Message ID:
200002181624.QAA03477@crypt.compulink.co.uk
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" }'
0
1
crypt% 

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?

Hugo
--- 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About