1

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?

0

2 Answers 2

4

You don't need take reference of scalars by \. You can directly do:

@numbers = ($num1, $num2);
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this merely stores the values of the scalars in the array, but that's surely what the OP wants.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.