Reputation: 575
I have the following code:
print Dumper($dec_res->{repositories}[0]);
print Dumper($dec_res->{repositories}[1]);
my @repos = ($dec_res->{repositories});
print scalar @repos . "\n";
and the output is the following:
$VAR1 = {
'status' => 'OK',
'name' => 'apir',
'svnUrl' => 'https://url.whatever/svn/apir',
'id' => 39,
'viewvcUrl' => 'https://url.whatever/viewvc/apir/'
};
$VAR1 = {
'status' => 'OK',
'name' => 'CCDS',
'svnUrl' => 'https://url.whatever/svn/CCDS',
'id' => 26,
'viewvcUrl' => 'https://url.whatever/viewvc/CCDS/'
};
1
So my question is why $dec_res->{repositories}
is clearly an array but @repos
is not?
Here I printed the size but even trying to access elements with $repos[0]
still returns an error.
Dumping $repos[0]
actually print the whole structure... like dumping $dec_res->{repositories}
Upvotes: 0
Views: 39
Reputation: 944204
$dec_res->{repositories}
is clearly an array
It isn't. It is an array reference.
but
@repos
is not?
It is an array.
You are creating a list that is one item long, and that item is the array reference. You then assign the list to the array, so the array holds that single item.
You need to dereference the array instead.
my @repos = @{$dec_res->{repositories}};
perlref explains more about references in Perl.
Upvotes: 9