Solved

Perl calling Perl

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl 101 11 72
PERL variable conundrum 9 89
Perl passing in variables to do substitution 6 66
Union rows in array that have common elements (Part 2) 4 70
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

25 Experts available now in Live!

Get 1:1 Help Now