Skip to content

Commit 105cb0c

Browse files
committed
doc declaration of multiple variables and destructuring
1 parent 601fb8e commit 105cb0c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/Language/variables.pod6

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,29 @@ introduce an alias into the symbol table.
518518
519519
# Available as $M::Var here.
520520
521+
=head2 Declaring a list of variables
522+
523+
The declarators C<my> and C<our> take a list of variables in parentheses as argument to declare more then one variable at a time.
524+
525+
my (@a, $s, %h);
526+
527+
This can be used in conjunction with X«destructureing assignment». Any
528+
assignment to such a list will take the number of elements provided in the left
529+
list and assign corresponding values from the right list to them. Any missing
530+
elements are left will result in undefined values according to the type of the
531+
variables.
532+
533+
my (Str $a, Str $b, Int $c) = <a b>;
534+
say [$a, $b, $c].perl;
535+
# OUTPUT«["a", "b", Int]␤»
536+
537+
To destructure a list into a single value create a list literal with one value.
538+
539+
sub f { 1,2,3 };
540+
my ($a,) = f;
541+
say $a.perl;
542+
# OUTPUT«1␤»
543+
521544
=head2 The C<has> Declarator
522545
523546
C<has> scopes attributes to instances of a class or role, and methods to

0 commit comments

Comments
 (0)