Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revised C<state> docs to reflect #perl6 comments
  • Loading branch information
dha committed Sep 14, 2015
1 parent a0163f7 commit 5ef883b
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/Language/variables.pod
Expand Up @@ -547,8 +547,8 @@ parentheses and for declaring a single variable, parentheses may be
omitted. Within a parenthesized list, C<$> can be used as a dummy
placeholder.
In fact, C<$> can be used as an anonymous state variable in subroutines
without a C<state> declaration.
In fact, C<$> can be used as an anonymous state variable without an
explicit C<state> declaration.
=begin code
Expand All @@ -566,11 +566,39 @@ produces
=end code
You could, for example, use C<$> in a one-liner to number the lines in a file.
Furthermore, state variables are not required to exist in
subroutines. You could, for example, use C<$> in a one-liner to
number the lines in a file.
=begin code
perl6 -ne 'say "{++$} $_"' example.txt
perl6 -ne 'say ++$ ~ " $_"' example.txt
=end code
Finally, if you were to use multiple anonymous state variables, they would
fuction independently.
=begin code
perl6 -e '{ say ++$; say $++ } for ^5'
=end code
would produce
=begin code
1
0
2
1
3
2
4
3
5
4
=end code
Expand Down

0 comments on commit 5ef883b

Please sign in to comment.