develooper Front page | perl.perl5.porters | Postings from December 2017

[perl #132644] The 'each' function documentation is missing someinformation.

Thread Previous | Thread Next
From:
karl williamson
Date:
December 22, 2017 17:40
Subject:
[perl #132644] The 'each' function documentation is missing someinformation.
Message ID:
rt-4.0.24-14012-1513964392-442.132644-75-0@perl.org
# New Ticket Created by  karl williamson 
# Please include the string:  [perl #132644]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132644 >


I am posting this for Dan Book, who is having trouble getting email to 
perlbug through.

The build options and version of perl is immaterial here.

1. When called in scalar context in a while loop, the condition is wrapped
implicitly in a 'defined' check, much like with 'readline'.

e.g. `while (my $key = each %hash) { ... }` becomes
`while (defined(my $key = each %hash)) { ... }`, and
`while (each %hash) { ... }` becomes `while (defined($_ = each %hash)) { 
... }`
(on 5.18+)

2. The iterator is not only shared and reset by calling 'keys' or 
'values', but
also by other calls to 'each' on the same hash or array, and by 
accessing the
hash in list context (such as for assignment to another structure, or 
passing
to a function) - this last one only applies to hashes, not arrays.


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