Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Perhaps I am misunderstanding the basic usage of wantarray, but it seems that the void/scalar/list context of a subroutine call propagates to sub-subroutine calls. Is there any way to avoid this, or to force a subroutine call to be executed in void context? For example, consider this code:
sub test { unless (defined wantarray) { print "test: wantarray is undefined\n"; } elsif (wantarray) { print "test: wantarray is true\n"; } else { print "test: wantarray is false\n"; } } sub test2 { test(); } my @t = test2();
Executing this prints the statement "test: wantarray is true". However, I would like a way to call test() from within test2(), and force void context. Is this possible?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: wantarray propagation?
by kennethk (Abbot) on May 20, 2011 at 19:58 UTC | |
Re: wantarray propagation?
by John M. Dlugosz (Monsignor) on May 20, 2011 at 19:58 UTC | |
Re: wantarray propagation?
by ikegami (Patriarch) on May 20, 2011 at 20:34 UTC | |
Re: wantarray propagation?
by Khen1950fx (Canon) on May 21, 2011 at 04:29 UTC |