How can I iterate over a Perl array reference?
arrays, perl, reference
Solution
I believe that:
$self->{myArray} returns a reference.
You want to return the array:
@{$self->{myArray}}
Problem
I have an array that is a member of a structure: ``` $self->{myArray} = ["value1", "value2"]; ``` And I'm trying to iterate over it using the following code: ``` my @myArray = $self->{myArray}; foreach my $foo (@myArray){ #Do something with the using $foo ... } ``` The problem is that the 'foreach' loop is executed only once (when I would expect it to execute twice, since @myArray has two elements: "value1" and "value2"). When I check the @myArray array size, I get that its size is 1. What am I doing wrong in this code?