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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |