@@ -2134,11 +2134,14 @@ X<array, iterator>
21342134index/value from an array
21352135
21362136When called on a hash in list context, returns a 2-element list
2137- consisting of the key and value for the next element of a hash. In Perl
2138- 5.12 and later only, it will also return the index and value for the next
2139- element of an array so that you can iterate over it; older Perls consider
2140- this a syntax error. When called in scalar context, returns only the key
2141- (not the value) in a hash, or the index in an array.
2137+ consisting of the key and value for the next element of a hash.
2138+ When called in scalar context, returns only the key (not the value).
2139+
2140+ When called on an array in list context, in Perl 5.12 and later, it
2141+ returns a 2-element list consisting of the index and value for the next
2142+ element of the array so that you can iterate over it; older Perls
2143+ consider this a syntax error. When called in scalar context, returns
2144+ only the index in the array.
21422145
21432146Hash entries are returned in an apparently random order. The actual random
21442147order is specific to a given hash; the exact same series of operations
@@ -2154,6 +2157,17 @@ details on why hash order is randomized. Aside from the guarantees
21542157provided here, the exact details of Perl's hash algorithm and the hash
21552158traversal order are subject to change in any release of Perl.
21562159
2160+ Array entries are returned lowest index first.
2161+
2162+ my @colors = (qw(red, green, blue));
2163+ while (my ($index, $value) = each @colors) {
2164+ print "[$index] = $value\n";
2165+ }
2166+
2167+ [0] = red
2168+ [1] = green
2169+ [2] = blue
2170+
21572171After C<each> has returned all entries from the hash or
21582172array, the next call to C<each> returns the empty list in
21592173list context and L<C<undef>|/undef EXPR> in scalar context; the next
@@ -2179,7 +2193,7 @@ implementation.
21792193
21802194The iterator used by C<each> is attached to the hash or array, and is
21812195shared between all iteration operations applied to the same hash or array.
2182- Thus all uses of C<each> on a single hash or array advance the same
2196+ Thus all uses of C<each> on a particular hash or array advance the same
21832197iterator location. All uses of C<each> are also subject to having the
21842198iterator reset by any use of C<keys> or C<values> on the same hash or
21852199array, or by the hash (but not array) being referenced in list context.
@@ -3934,10 +3948,12 @@ X<keys> X<key>
39343948=for Pod::Functions retrieve list of indices from a hash or array
39353949
39363950Called in list context, returns a list consisting of all the keys of the
3937- named hash, or in Perl 5.12 or later only , the indices of an array. Perl
3951+ named hash, or in Perl 5.12 or later, the indices of an array. Perl
39383952releases prior to 5.12 will produce a syntax error if you try to use an
39393953array argument. In scalar context, returns the number of keys or indices.
39403954
3955+ Array entries are returned lowest index first.
3956+
39413957Hash entries are returned in an apparently random order. The actual random
39423958order is specific to a given hash; the exact same series of operations
39433959on two hashes may result in a different order for each hash. Any insertion
@@ -3986,7 +4002,7 @@ sort of a hash by its values:
39864002 printf "%4d %s\n", $hash{$key}, $key;
39874003 }
39884004
3989- Used as an lvalue C<keys> allows you to increase the
4005+ Used as an lvalue on a hash, C<keys> allows you to increase the
39904006number of hash buckets
39914007allocated for the given hash. This can gain you a measure of efficiency if
39924008you know the hash is going to get big. (This is similar to pre-extending
@@ -4000,8 +4016,9 @@ buckets will be retained even if you do C<%hash = ()>, use C<undef
40004016%hash> if you want to free the storage while C<%hash> is still in scope.
40014017You can't shrink the number of buckets allocated for the hash using
40024018C<keys> in this way (but you needn't worry about doing
4003- this by accident, as trying has no effect). C<keys @array> in an lvalue
4004- context is a syntax error.
4019+ this by accident, as trying has no effect).
4020+
4021+ C<keys @array> in an lvalue context is a syntax error.
40054022
40064023Starting with Perl 5.14, an experimental feature allowed
40074024C<keys> to take a scalar expression. This experiment has
@@ -10497,10 +10514,12 @@ X<values>
1049710514
1049810515=for Pod::Functions return a list of the values in a hash or array
1049910516
10500- In list context, returns a list consisting of all the values of the named
10501- hash. In Perl 5.12 or later only, will also return a list of the values of
10502- an array; prior to that release, attempting to use an array argument will
10503- produce a syntax error. In scalar context, returns the number of values.
10517+ Called in list context, returns a list consisting of all the value of the
10518+ named hash, or in Perl 5.12 or later, the values of an array. Perl
10519+ releases prior to 5.12 will produce a syntax error if you try to use an
10520+ array argument. In scalar context, returns the number of keys or indices.
10521+
10522+ Array entries are returned in the order of lowest index first.
1050410523
1050510524Hash entries are returned in an apparently random order. The actual random
1050610525order is specific to a given hash; the exact same series of operations
0 commit comments