in reply to check for wantarray?

What does wantarray have to do with it? All of the following return something different based on context:

What about

sub foo { ...; bar() }

The whole "independent of parameters" bit is problematic too.

sub { ...; if ($_[0]) { $foo } else { @bar } }

It might be possible to identify some subs that only return a scalar by poking at the opcode tree, but for many subs, it probably would be quite hard to tell.

Replies are listed 'Best First'.
Re^2: check for wantarray?
by TGI (Parson) on Dec 27, 2008 at 17:16 UTC

    Excellent point. Here's one that surprised the hell out of me one time:

    sub { ...; $x..$y }

    Holy flip-flop operator, Batman!

    I thought I was going crazy until I reread the relevant bits of perlop.


    TGI says moo