Skip to content

Commit 9bdd74b

Browse files
committed
improve example of placeholder variables
This better represents the intended usage, such as { $^b cmp $^a }, and cautions the reader against names that require mental sorting in order to properly write or understand the code.
1 parent c073e8e commit 9bdd74b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

doc/Language/variables.pod

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,23 @@ that block. So the block in the code
301301
302302
=for code :allow<B>
303303
for ^4 {
304-
say "B<$^second> follows B<$^first>";
304+
say "B<$^b> follows B<$^a>";
305305
}
306306
307307
which prints
308308
309309
1 follows 0
310310
3 follows 2
311311
312-
has two formal parameters, namely C<$first> and C<$second>. Note that even
313-
though C<$^second> appears before C<$^first> in the code, C<$^first> is
314-
still the first formal parameter to that block. This is because the
315-
placeholder variables are sorted in Unicode order. If you have self-declared
316-
a parameter using C<$^a> once, you may refer to it using only C<$a>
317-
thereafter.
312+
has two formal parameters, namely C<$a> and C<$b>. Note that even though C<$^b>
313+
appears before C<$^a> in the code, C<$^a> is still the first formal parameter
314+
to that block. This is because the placeholder variables are sorted in Unicode
315+
order. If you have self-declared a parameter using C<$^a> once, you may refer
316+
to it using only C<$a> thereafter.
317+
318+
Although it is possible to use nearly any valid identifier as a placeholder
319+
variable, it's recommended to use short names or ones that can be trivially
320+
understood in the correct order, to avoid surprise on behalf of the reader.
318321
319322
Subroutines may also make use of placeholder variables but only if they do
320323
not have an explicit parameter list. This is true for normal blocks too.

0 commit comments

Comments
 (0)