diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-08-01 14:17:20 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-08-01 20:38:18 -0700 |
commit | e6a0db3e94c42381d26fd9cde58d49b99c99cabb (patch) | |
tree | c3811098c441458e113028236af7be4c4250d56a /pod/perlfunc.pod | |
parent | b5a648148c71e82a615a5ed312204978f88e1def (diff) | |
download | perl-e6a0db3e94c42381d26fd9cde58d49b99c99cabb.tar.gz |
perlfunc: Document implicit $_ in while(each)
Diffstat (limited to 'pod/perlfunc.pod')
-rw-r--r-- | pod/perlfunc.pod | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index b76da4a3ce..7203b2b703 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1686,6 +1686,13 @@ The exact behaviour may change in a future version of Perl. while (($key,$value) = each $hashref) { ... } +As of Perl 5.18 you can use a bare C<each> in a C<while> loop, +which will set C<$_> on every iteration. + + while(each %ENV) { + print "$_=$ENV{$_}\n"; + } + To avoid confusing would-be users of your code who are running earlier versions of Perl with mysterious syntax errors, put this sort of thing at the top of your file to signal that your code will work I<only> on Perls of @@ -1693,6 +1700,7 @@ a recent vintage: use 5.012; # so keys/values/each work on arrays use 5.014; # so keys/values/each work on scalars (experimental) + use 5.018; # so each assigns to $_ in a lone while test See also C<keys>, C<values>, and C<sort>. |