in reply to Determining subroutine return type
The caller can't tell the difference between a list of one item and a scalar, so you won't get perfect results. Maybe the following will do what you want, though:
sub determineType { my $sub_ref = shift; my @rval = $sub_ref(@_); return $rval[0] if @rval <= 1; return @rval if @rval >= 2; my $rval = $rval[0]; return @$rval if (ref($rval) eq 'ARRAY'); return %$rval if (ref($rval) eq 'HASH'); }
By the way, you said "reference to a list", but there is no such thing. You meant "reference to an array".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determining subroutine return type
by satchm0h (Beadle) on Feb 24, 2005 at 22:43 UTC |