简体   繁体   中英

Need help getting perl array out of scalar context

I have a perl array I need to store in the following way:

 $self->{spec}->{allImages} = @allImages;

Then I need to retrieve the contents later:

 print Dumper($self->{spec}->{allImages});

This yields:

 $VAR1 = 10;

(the number of items in the array).

How can I break out of scalar context and get $self->{spec}->{allImages} back as a list?

Each hash value can only be a scalar.

You must store a reference to the array:

$self->{spec}->{allImages} = \@allImages;

http://perldoc.perl.org/perlreftut.html will give you more tutorial.

You need to change the assignment:

$self->{spec}->{allImages} = \@allImages;

This creates an array-ref that you can use.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM