http://qs1969.pair.com?node_id=613608

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

I have a method called func1
sub func1{
....

...
return ($a,$b);
}

Now I want a one liner so that I can use the arrayrefs returned from that method

I can do like this

@a=func1($a,$b);

and use \@a any where I required.
But I dont want this instead I want someway to use like \@func1();
Can anyone suggest what shud I do.

Replies are listed 'Best First'.
Re: Array refs
by Corion (Patriarch) on May 04, 2007 at 16:17 UTC

    How about

    [ func1( $x, $y ) ]

    You could also modify your function to return an arrayref instead of an array...

Re: Array refs
by j1n3l0 (Friar) on May 04, 2007 at 16:34 UTC
    I would return an arrayref instead
    sub func1 { # do some stuff return [$a, $b]; }
    Then you can do stuff like
    $ref = fuc1(); #or @ref = @{func1()};
    Hope that helps ;)
Re: Array refs
by RL (Monk) on May 04, 2007 at 17:11 UTC
    sub func1{ .... ... return ($a,$b); }

    Now I want a one liner so that I can use the arrayrefs returned from that method

    Am I right to assume $a and $b are arrayrefs already?

    If yes then something like the following may work for you

    my ($aryref_a, $aryref_b) = func1();

    RL