File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -518,6 +518,29 @@ introduce an alias into the symbol table.
518
518
519
519
# Available as $M::Var here.
520
520
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
+
521
544
= head2 The C < has > Declarator
522
545
523
546
C < has > scopes attributes to instances of a class or role, and methods to
You can’t perform that action at this time.
0 commit comments