Along with having an array reference as opposed to a hash reference, ref($aref) returns ARRAY, not LIST, so that'll never catch.
Here's a basic example for review and to do some testing with:
:
use warnings;
use strict;
my $struct = [
{
1 => 'a',
2 => 'b',
},
[
1,
2,
3,
],
{
3 => 'c',
4 => 'd',
},
];
thing($struct);
sub thing {
my ($aref) = @_;
for my $elem (@$aref){
if (ref $elem eq 'ARRAY'){
print "array:\n";
print "$_\n" for @$elem;
}
elsif (ref $elem eq 'HASH'){
print "hash:\n";
print "$_ => $elem->{$_}\n" for keys %$elem;
}
else {
die "element is not an allowed ref\n";
}
}
}
Output:
hash:
1 => a
2 => b
array:
1
2
3
hash:
3 => c
4 => d