in reply to uber-reference

API->use_the_new_way; my @result; if (wantarray) { @result = $func->(@_); } else { $result[0] = $func->(@_); } API->go_back_to_the_old_way; return wantarray ? @result : $result[0];

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: uber-reference
by jettero (Monsignor) on Dec 30, 2000 at 01:06 UTC

    update: I had no idea that wantarray was a function when I first wrote this response... I figured that was pseudo-code or something. :) Who knew (besides merlyn and everyone)?


    This is sorta what we've been thinkin' about doing, where the wantarray would get decided depending on weather or not the function was called with _r or _ra, but I really really wanted a way where we didn't have to specify the wantarray... that it would just figure it out on it's own ...

    oh well eh... *sigh*

    we were also thinkin' like:

    API->new_way; my @ret = $func->(@_); API->old_way; return @ret==1 ? $ret[0] : @ret;
    Which is a solution we just came up with a little while ago ... I can't think of any reason why it wouldn't work since it would probably work with hashes, arrays, scalars, and ... what else is there? Can you think of an reason why this method is dumb?

      But merlyn's way does figure it out automatically on its own.

              - tye (but my friends call me "Tye")