Can I bind multiple variables at once?

466 Views Asked by At

The following line declares a variable and binds it to the number on the right-hand side.

my $a := 42;

The effect is that $a is not a Scalar, but an Int, as can be seen by

say $a.VAR.^name;

My question is, can I bind multiple variables in one declaration? This doesn't work:

my ($a, $b) := 17, 42;

because, as can be seen using say $a.VAR.^name, both $a and $b are Scalars now. (I think I understand why this happens, the question is whether there is a different approach that would bind both $a and $b to given Ints without creating Scalars.)

Furthermore, is there any difference between using := and = in this case?

1

There are 1 best solutions below

2
On BEST ANSWER

You can use sigilless containers:

my (\a, \b) := 17,42;
say a.VAR.^name; # Int

Sigilless variables do not have an associated container