I have a function that returns two 'array's, but I was having difficulty assigning these results to two 'array' variables.
my (@A, @N) = volver_dos_arrays;
dd @A; # muestra lo que está dentro de @A (dd = "data dumper")
dd @N;
sub volver_dos_arrays
{
my @alfa = <A B C>;
my @num = 1, 2, 3;
return @alfa, @num;
}
It results in the following: in which we can see that the first 'array' stored the two 'arrays' that the function returned:
Array @A = [["A", "B", "C"], [1, 2, 3]]
Array @N = []
But, I wanted it to be like this:
Array @A = ["A", "B", "C"]
Array @N = [1, 2, 3]
I know the following works, but I don't like saving an array in a scalar. I don't want to change the sigil of the @A
nor the @N
.
my ($A, $N) = volver_dos_arrays;
dd $A;
dd $N;
sub volver_dos_arrays
{
my @alpha = <A B C>;
my @num = 1, 2, 3;
return @alpha, @num;
}
How can I do this without changing the sigils?
I learned how to do it, but I still ask the question because it stumped me for a couple of hours. I make an answer if no one gives an answer similar to what I found out.