Search code examples
arraysperlscalar-context

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?


Solution

  • 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.