I have an array
my @numbers;
my $num1 = 23;
my $num2 = 4;
@numbers=(\$num1 ,\$num2);
print @numbers;
then on printing the array i get something like this SCALAR(0x6a16ec8), i want the values. How do i properly store the scalar values in the array?
You don't need take reference of scalars by \\
. You can directly do:
@numbers = ($num1, $num2);
You stored a reference in your array.
@numbers=(\$num1 ,\$num2);
Delete the "\\" in front of your Variables and it work.
@numbers=($num1 ,$num2);
A other simple Way is to use the push function from perl.
push(@numbers,($num1,$num2));
With push you append your array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.