It seems my code cannot iterate over an array stored in a hash.
What did I miss ?
#!/usr/bin/env perl
use Data::Dumper;
my $data = {array => ['a', 'b', 'c']};
my @array = $data->{array};
print Dumper(@array); # It looks like $data->{array} is an array
print "Ref: ".ref($data->{array})."\n"; # And this array is indeed an array
foreach ($data->{array}) { print "$_\n"; } # But this doesn't work
foreach (@array) { print "$_\n"; } # Neither this one
# But with a regular array it works...
my @myNames = ('Larry', 'Curly', 'Moe');
foreach (@myNames) { print "$_\n"; }
My output:
$VAR1 = [
'a',
'b',
'c'
];
$VAR1 = 'a';
Ref: ARRAY
ARRAY(0x8002bcf8)
ARRAY(0x8002bcf8)
Larry
Curly
Moe
I am pretty confused with REF/SCALAR types. Sometime Perl takes values as references sometime not. In this case, because I get 'ARRAY' from the ref function, I guess $->{array} doesn't give me an array but a reference to the array.
I have also tried @$data->{array} without success.