Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Array refs

by palette (Scribe)
on May 04, 2007 at 16:10 UTC ( [id://613608]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://613608]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-19 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found