in reply to How do you test for return type($,@,%)?
One quick way I can think of to get around this is by passing references. For example,$var = mysub(); @var = mysub(); %var = mysub(); sub mysub { print "You want a scalar\n" unless wantarray; print "You either want a hash or an array\n" if wantarray; }
Hope that helps,my($var,@var,%var); &mysub(\$var); &mysub(\@var); &mysub(\%var); sub mysub { my($ref) = shift; print "You want a scalar\n" if ref($ref) eq 'SCALAR'; print "You want an array\n" if ref($ref) eq 'ARRAY'; print "You want a hash\n" if ref($ref) eq 'HASH'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Answer: How do you test for return type($,@,%)?
by chromatic (Archbishop) on Jun 24, 2000 at 02:11 UTC |