I wrote the same thing, tried it with his test and realized that he differentiated between scalar and void context. FWIW my first try involved:
then I realized the problem, and came up with:push my @result, wantarray ? &inner_func() : scalar &inner_func();
Ick. :-( There are times you should be verbose. This is one of them...sub outer_func { my @result; defined(wantarray) ? (push @result, wantarray ? &inner_func() : scalar &inner_func()) : &inner_func(); # do some other stuff return (wantarray ? (@result) : $result[0]); }
Personally I think your approach of separating the cases is cleaner. But honestly I have never once encountered a situation where I needed to propagate context in this manner...
In reply to RE (tilly) 2: Propagating calling context
by tilly
in thread Propagating calling context
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |