in reply to subroutines & functions
You're asking what context the function is being called in. There are (basically) three contexts in Perl - void, scalar and list. You can use the wantarray function to determine how your function has been called.
sub how { my $how = wantarray; if (defined $how) { if ($how) { print "list\n"; } else { print "scalar\n"; } } else { print "void\n"; } } how; my $s = how; my @a = how;
For your question I think you just need to check if the return value from wantarray is defined.
--"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: subroutines & functions
by bart (Canon) on Jun 23, 2003 at 02:07 UTC | |
by tye (Sage) on Jun 23, 2003 at 04:15 UTC |