Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Perl calling Perl

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to remove invisible characters with perl 2 89
Migrate OTRS to newest version. 1 367
Insert Text into odbc.ini file 15 67
parse a file and get data out 11 75
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 …
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…

808 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