You create an array with one element (a reference to an array) with
my @fishes = $data->{fish};
Then you iterate over the elements of that array with
foreach my $fish (@fishes)
That's just a really weird way of doing
my $fish = $data->{fish};
Let's use that, but rename $fish
to $fishes
, and $innerFish
to $fish
.
my $fishes = $data->{fish};
for my $fish (@$fishes) {
print($fish->{displayName}, " is ", $fish->{description}, "\n");
}
Don't forget to use the ForceArray => [qw( fish )]
option to make sure the code works when you only have a single fish.