Solved

Perl calling Perl

Posted on 2012-04-08
5
206 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now