in reply to Determining subroutine return type
if the subroutine returns a list I don't want to evaluate it in scalar context and end up with the length.You wouldn't. You'd get the last element of the list. Not that that's much preferable. If you assigned the results to a list containing one scalar, you'd get the first. You'd have to do the $bar = () = foo trick to get the length.
my $foo = sub { return (4,5,8) }; # evaluate in (too-short) list context: my ($bar) = &$foo; print "Bar=$bar\n"; # evaluate in scalar context: $bar = &$foo; print "Bar=$bar\n"; # array context, sort of $bar = () = &$foo; print "Bar=$bar\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determining subroutine return type
by sandfly (Beadle) on Feb 24, 2005 at 23:16 UTC |