tempfoo has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to return a reference to the result of a function? For example:
$ref=\(split(//, "tempfoo")); print $ref->[0], "\n"; # should print "t"
I'm asking because it doesn't work. Thanks for any pointers....

Replies are listed 'Best First'.
Re: return a reference to the result of a function
by grantm (Parson) on Nov 22, 2002 at 18:48 UTC

    No, but if you just want $ref to be a reference to an array of the values returned then try:

    $ref = [ split(//, "tempfoo") ];
Re: return a reference to the result of a function
by particle (Vicar) on Nov 22, 2002 at 18:51 UTC
    $ref = [ split //, 'tempfoo' ]; print $ref->[0], $/; ## prints: t

    ~Particle *accelerates*

Re: return a reference to the result of a function
by dvergin (Monsignor) on Nov 22, 2002 at 23:48 UTC
    Alternate approach:
    my $aref; @$aref = split //, 'tempfoo'; print $aref->[0];

    ------------------------------------------------------------
    "Perl is a mess and that's good because the
    problem space is also a mess.
    " - Larry Wall