Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I bind multiple variables at once?

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?

like image 844
Nikola Benes Avatar asked Jun 27 '21 15:06

Nikola Benes


People also ask

Can you assign multiple variables at once in C?

If your variables are the same type, you can define multiple variables in one declaration statement. For example: int age, reach; In this example, two variables called age and reach would be defined as integers.

Can a variable hold two values at the same time?

A variable can only store one value at a time – a number or a string.

How do I declare more than one variable in a list?

To declare more than one variable of the same type, you can use a comma-separated list: You can also assign the same value to multiple variables in one line:

Can a set of numbers hold more than one variable?

Actually, any variable can hold multiple variables at a time if you just make a suitable conversion. For example the set of ordered pair of numbers have a one to one correspondence with the set of numbers. For natural numbers for example. and so on. so the set of natural numbers N has the same number of elements as the set of NxN or N^2 and so on.

How to assign value to multiple variables in Python?

Assign Value to Multiple Variables Python allows you to assign values to multiple variables in one line: Example x, y, z = "Orange", "Banana", "Cherry" print(x) print(y)

How to merge multiple data sets in R with binds and joins?

How to Merge Multiple Data Sets in R With Binds and Joins 1 Objectives. The only library we need is tidyverse. ... 2 Common Errors and Issues with Binds and Joins. There will be quite a few errors coming up. ... 3 Rename Some Columns. We can do this a lot of ways, but this is the simplest illustration I could think to use. ... 4 Conclusion


1 Answers

You can use sigilless containers:

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

Sigilless variables do not have an associated container

like image 51
jjmerelo Avatar answered Oct 19 '22 13:10

jjmerelo