in reply to Re: (jeffa) Re: Returning data from wrapped sub
in thread Returning data from wrapped sub

Nope - try this:
use strict; use Data::Dumper; my $ref = \&bar; my @arry = foo($ref); $ref = \&baz; my $scal = foo($ref); print Dumper @arry; print Dumper $scal; sub foo { my $ref = shift; my @a = &$ref; return wantarray ? @a : $a[0]; } sub bar { (1..4) } sub baz { [(1..4)] }

jeffa

Replies are listed 'Best First'.
Re: (jeffa) 3Re: Returning data from wrapped sub
by japhy (Canon) on Aug 30, 2001 at 00:57 UTC
    That does not answer his question. If the return value of a function call is being stored in a list, the function is called in "array" context.
    @x = func() ; # list context ($x) = func() ; # list context $x = (func())[1]; # list context
    Read my article on lists.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re (tilly) 4: Returning data from wrapped sub
by tilly (Archbishop) on Aug 30, 2001 at 05:20 UTC
    Try it with:
    $ref = sub {localtime(@_)};
    You will very quickly find that your wrapper has changed rather dramatically what happens in scalar context.
Re: (jeffa) 3Re: Returning data from wrapped sub
by suaveant (Parson) on Aug 30, 2001 at 01:09 UTC
    Yep... this does work... I guess I just didn't fully understand how context stuff works...

                    - Ant
                    - Some of my best work - Fish Dinner