Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
sub inner_func { if (wantarray) { print "ARRAY CONTEXT\n"; } elsif (defined wantarray) { print "SCALAR CONTEXT\n"; } else { print "VOID CONTEXT\n"; } } sub outer_func { my @result; if (wantarray) { # propagate context @result = inner_func(); } elsif (defined wantarray) { $result[0] = inner_func(); } else { inner_func(); } # do some other stuff return (wantarray ? (@result) : $result[0]); } my @r = outer_func(); my $r = outer_func(); outer_func();
doesn't count, since I need to do some work after calling inner_func but before returning the results.sub outer_func { inner_func() }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Propagating calling context
by merlyn (Sage) on Aug 22, 2000 at 05:25 UTC | |
by tilly (Archbishop) on Aug 22, 2000 at 05:43 UTC | |
by merlyn (Sage) on Aug 22, 2000 at 15:43 UTC |