Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Communication between scripts

by glemley8 (Acolyte)
on Dec 17, 2012 at 21:13 UTC ( #1009233=perlquestion: print w/replies, xml ) Need Help??

glemley8 has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a script that runs several "subscripts", using the 'system' command. I'd like a subscript to be able to declare and communicate a variable to my master script. For example, if "event1" occurs during the subscript, tell the master script that it did occur. I tried using the "our" variable declaration but had no luck (I've successfully used it elsewhere though). I'm sure this is a very elementary thing, but I'm having trouble finding the correct way to do it.

Replies are listed 'Best First'.
Re: Communication between scripts
by SuicideJunkie (Vicar) on Dec 17, 2012 at 21:34 UTC

    Peruse perlipc and take a look to see what applies best to you. Pipes, sockets, signals, or perhaps just print to STDOUT and capture it with backticks.

Re: Communication between scripts
by kennethk (Abbot) on Dec 17, 2012 at 22:13 UTC

    Also common would be to centralize and use modules instead of cascading scripts.

    If you are set on multiple scripts, you can use globals (our) combined with do (or require) rather than system. But this is probably not a good idea for new code, since this gets messy fast, and the execution environments can have odd effects on each other.

    #!/usr/bin/perl -w use strict; our $x = 1; require 'script2.pl'; print $x;
    #!/usr/bin/perl -w use strict; our $x = 2;

    SuicideJunkie's suggestions are where you should look first (maybe even w/ a fork and exec); however, if you are dealing with legacy, this might help.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1009233]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2021-12-06 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (32 votes). Check out past polls.

    Notices?