If $query is a CGI.pm object, then the best way is probably:

myfunc( return => $query->param_fetch("return"), authors => $query->param_fetch("authors") );

(with many more parameters)

Oh, well, then you probably want this instead:

myfunc( map { $_ => $query->param_fetch($_) } qw( return authors to their stables immediately ) ) # or myfunc( map { $_ => $query->param_fetch($_) } $query->param() )

For the more general problem of "How do I get a reference to a subroutine return value?" (which I thought was an interesting question so I did some investigating), the answer is "you can't". You can get a reference to copies of subroutine return values via:

$sv= \sub_returning_scalar(); $av= [sub_returning_list()]; $hv= {sub_returning_hash()};

So if you follow the advice of those who answered before me but part of your unstated goal was to allow the subroutine to modify the parameters such that $query would notice the modifications, then you will fail because those array references will only allow you to modify copies of those values.

The methods I suggested will allow myfunc to modify the CGI parameters directly. This can certainly be a disadvantage if you wanted myfunc to be able to futz with those arrays without affecting the CGI $query object.

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

In reply to (tye)Re: How do I get a reference to a subroutine return value? by tye
in thread How do I get a reference to a subroutine return value? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.