You could just use
ref
my $item1 = {
result => { value => 'a' },
};
my $item2 = {
result => [
{ value => 'b' },
{ value => 'c' },
],
};
parse_result( $item1->{'result'} );
parse_result( $item2->{'result'} );
sub parse_result {
my $result = shift;
if ( ref $result eq 'HASH' ) {
print "Parsing hashref\n";
print "Value: $result->{'value'}\n";
}
elsif ( ref $result eq 'ARRAY' ) {
print "Parsing arrayref\n";
my @values;
for my $item ( @$result ) {
push( @values, $item->{'value'} );
}
print "Values: @values\n";
}
}
OUTPUT
Parsing hashref
Value: a
Parsing arrayref
Values: b c