If this is a problem you can call all subroutines in array context
It's called list context. Arrays have nothing to do with it.
Messy but would take care of the problem.
Not necessarily.
sub f { return @_ }
sub g { return [ @_ ] }
my $d = [];
my @f = f($d); printf("%d element(s), first=%s\n", 0+@f, $f[0]);
my @g = g($d); printf("%d element(s), first=%s\n", 0+@g, $g[0]);
1 element(s), first=ARRAY(0x235f6c)
1 element(s), first=ARRAY(0x236020)
This is how I handle some XML data structures deparsed from API calls to certain applications that can return an array of hashrefs, an arrayref of hashrefs, a single hashref or undefined.
Let's hope not since your code can't differentiate between list of hashrefs and a single hashref. The latter is just a short list of hashrefs. (I presumed you meant "list of hashref" when you said "array of hashref" since it's impossible to return an array.)
|