Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Perl calling Perl

Hello,

I am thinknig about the following:

Script1 is running continuously and doing its job: keeping track of things, logging them in memory. Script2 runs from time to time and needs to get info from Script1.

So Script2 needs to be able to call the running Script1 or call a sub or function in running Script1 and get feedback from it.

An option would be a small intermediate database but I need to install just for this small stuff a DB engine on the machine. So I will do this only if I really, really need to.

Ain't there a faster, nicer way to exchange data between 2 scripts? Is there a way to share memory between scripts? are there other way to get this functionality? ... ?
0
Marc_Engrie
Asked:
Marc_Engrie
  • 3
  • 2
1 Solution
 
FishMongerCommented:
You need to provide more details but my first suggestion would be to turn script2 into a proper module and load it (via a use statement) in script1.  Then in script1 you could execute the the sub(s) defined in that module and pass them the required arguments.
0
 
FishMongerCommented:
If that's more than what you want to do, then you could use the Storable module and have script1 save the required data structure to disk and then script2 would use the Storable module to retrieve that data structure.
0
 
Marc_EngrieAuthor Commented:
Looks like a possible solution.
I'll give it a try.

Although I was/am more thinking towards that Script2 would be able to call a sub from Script1 without saving to disk.

Another thought is that Script1 and Script2 share a same space in memory to be able to exchange data bewteen both scripts.
0
 
Marc_EngrieAuthor Commented:
Hello,

I solved my 'problem' by using IO:Socket:INET.

I created a socket server routine inside Script1. Script2 has a socket client. Whenever Script2 needs data from Script1, it sends its request to the server in Script1 and wait for feedback. The feedback is the data Script2 needs.

Thx away for the information on Storable module. It might become handy one day.
0
 
FishMongerCommented:
Although I was/am more thinking towards that Script2 would be able to call a sub from Script1 without saving to disk.
To do that, script1 would/should be turned into a module and exports its subs, then in script2 you'd load script1 with a use statement and call the subs as needed.  Another option, which is similar, but not as good, would be to execute script1 inside script2 via a do statement.

Another thought is that Script1 and Script2 share a same space in memory to be able to exchange data bewteen both scripts.
Sorry, that's not how Perl scripts work.  The closest method I can think of to achieve that would be to use the Storable module.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now