Perl/RFCs/rfcs/rfc0001 の翻訳
この文書は、Perl/RFCs/rfcs/rfc0001を翻訳したものです。
0e57765a667b340b709e16a96cbf10df
7d68f6c97a3ff2dc413ba834324a6ed3
05b623612e9222e3c3ad0243b54612fd
68da2aaa6a616b93ef162ce84dde59b7
Implement the currently illegal syntax `for my ($key, $value) (%hash) { ... }` to act as two-at-a-time iteration over hashes. This approach is not specific to hashes - it generalises to n-at-a-time over any list.
c74ce0b34b5157849c9b1a38acfba306
The `each` function is generally discouraged due to implementation details, but is still the most "pretty" and concise way to write such a loop:
a5885e8f5ba2f1352fd7d0678b196dfe
An alternative to this would be a syntax to alias multiple items per iteration in a `for` loop.
ddd1cb6445b86ef1fde32fd980ae36a0
This generalizes as a "bundler" - to alias a number of elements from the list equal to the number of variables specified. Such as:
bb408199a87809eef30842a23e38fb26
831d2d39260be23b69c551b14ff2b114
The existing syntax to iterate over the keys and values of a hash:
a5885e8f5ba2f1352fd7d0678b196dfe
suffers from several problems
7e6895342c26a2cef19c749b69622751
You *can* write it in two lines as
8c8af1b90072da6de80042dc9f6837db
(three if `%hash` is actually a complex expression you don't want to evaluate twice)
but that's not perceived as an obvious "win" over the one-liner.
The more general *n-at-a-time* iteration of an array problem doesn't have a simple generic solution. For example, you can **destructively** iterate an **array**:
19dbb9e904ac39419e067feadc2d424b
(with that *3* needing to be written out explicitly - it can't derived from the number of lexicals)
You can iterate over an list non-destructively like this:
828f596052072d9389c8911d18c9f23f
but that
f32292144ca6fe1b67d053621c6438e6
The proposed syntax solves all of these problems.
23bbfee52618e1bfb06eb381662d779f
```
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index fe511f052e..490119d00e 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -282,6 +282,14 @@ The following compound statements may be used to control flow:
73cad8774c582d5ae045e39615269f0e
+As of Perl 5.36, you can iterate over multiple values at a time by specifying
+a list of lexicals within parentheses
+
+ no warnings "experimental::for_list";
+ LABEL for my (VAR, VAR) (LIST) BLOCK
+ LABEL for my (VAR, VAR) (LIST) BLOCK continue BLOCK
+ LABEL foreach my (VAR, VAR) (LIST) BLOCK
+ LABEL foreach my (VAR, VAR) (LIST) BLOCK continue BLOCK
+
If enabled by the experimental C
feature, the following may also be used
9dc0d25414337dfec4ee7954be6168b5
@@ -549,6 +557,14 @@ followed by C. To use this form, you must enable the C
feature via C