Solved

Perl calling Perl

Posted on 2012-04-08
5
210 Views
Last Modified: 2012-08-14
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
Comment
Question by:Marc_Engrie
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 37821415
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
 
LVL 28

Expert Comment

by:FishMonger
ID: 37821456
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
 

Author Comment

by:Marc_Engrie
ID: 37822929
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
 

Author Comment

by:Marc_Engrie
ID: 37823826
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
 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
ID: 37823860
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question