Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Executing functions from another process

by davido (Cardinal)
on Jan 23, 2014 at 19:11 UTC ( #1071804=note: print w/replies, xml ) Need Help??

in reply to Executing functions from another process

Set up a dispatch table in the process that is to execute functions. Pass function calls and parameters as JSON from one process to the other. On the recipient side, decode the JSON, which will contain a dispatch table entry key, and the parameters to pass. mucking in the symbol table that way, and no obscure, one-off protocols for data exchange.


  • Comment on Re: Executing functions from another process

Replies are listed 'Best First'.
Re^2: Executing functions from another process
by gri6507 (Deacon) on Jan 23, 2014 at 19:25 UTC
    Conceptually I understand how this could be done, but I have two problems with this proposed solution. In my full application, the actual functions being executed are not even defined in the same script. They get pulled in via a do() call to another script. It would be a maintenance headache to maintain a dispatch table in this script. It's much easier to simply get the function name and execute it as a function ref.

    The second problem is more practical. The prototypes of functions that get called are all different. Some have no args, some have one scalar, others have multiple array refs, etc. How could I set up a generic JSON message to convey such a varying list of parameters?

      How would you set up the parameters in Perl?

      Just set up the parameters, and then print them as encoded JSON. On the other side, reverse the process.

      For example, the following structure should work fine for passing parameters.

      { "parameters": [], "function": "frobnitz" }

      Also, maybe JSON::RPC is of help.

        Ok. I've tried it and it works great, but with one key problem. It appears that when JSON encodes the parameters, it does so "by value". In other words, if my function call is supposed to take an argument by reference to a scalar, with the intent of modifying it, this method does not work.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-08-15 08:12 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (78 votes). Check out past polls.