prints:foreach my $run ('a' .. 'c') { my $x = S($run); print "$run : $x\n"; } sub S { my $mode = shift; return 42 if $mode eq 'a'; return (42) if $mode eq 'b'; my @l = (42); return @l if $mode eq 'c'; }
a : 42 b : 42 c : 1
How do the caller tell if S returned a scalar or an array? And how do I make it detect it and take propper action?
If I just collect everything in an array how do I tell if it returned a scalar or a single element list?
In reply to Detecting type of output from subs by mogul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |