Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

(tye)Re: How do I get a reference to a subroutine return value?

by tye (Sage)
on Mar 03, 2001 at 11:48 UTC ( [id://61993]=note: print w/replies, xml ) Need Help??


in reply to How do I get a reference to a subroutine return value?

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")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found