Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How to share global variable between two program instances ??

by sugarkannan (Novice)
on Dec 19, 2005 at 18:57 UTC ( [id://517855]=perlquestion: print w/replies, xml ) Need Help??

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

How to share global variable between two program instances ??

-Sugar
  • Comment on How to share global variable between two program instances ??

Replies are listed 'Best First'.
Re: How to share global variable between two program instances ??
by Old_Gray_Bear (Bishop) on Dec 19, 2005 at 19:19 UTC
    Very Carefully.

    If you have both instances running on the same machine at the same time, take a look a using a tied-hash (particularly if there are more than one variable involved).

    If you have successive executions, then you can read and write the state to a configuration file. (See CPAN for your choices here.)

    If you have instances running at the same time on different machines, the co-ordination problem gets tougher. Sockets will come into play and a lot of work to verify that your 'global variables' really are in sync across the Network.

    If the globals are read-only, I'd be tempted to design a forked master/worker solution, where the globals are set by the master, possible by reading a state-file, before forking off a worker task to complete the process.

    Which ever way you choose, there will be issues of synchrony and update consistancy that you will have to address.

    ----
    I Go Back to Sleep, Now.

    OGB

Re: How to share global variable between two program instances ??
by borisz (Canon) on Dec 19, 2005 at 19:10 UTC
Re: How to share global variable between two program instances ??
by l3v3l (Monk) on Dec 19, 2005 at 19:20 UTC
    If your program needs access to variables that persist from one invocation to the next (and are optionally modified between invocations) there is a nice merlyn article on just that subject!
Re: How to share global variable between two program instances ??
by GrandFather (Saint) on Dec 19, 2005 at 19:22 UTC

    If you are running two instances seperated in time (one after the other) then XML::Simple and Storable are usefull.


    DWIM is Perl's answer to Gödel
Re: How to share global variable between two program instances ??
by tphyahoo (Vicar) on Dec 19, 2005 at 19:02 UTC
    Use an ini file, which gets read by both programs.

    Or, have both programs use the same module, and the global variable is defined there.

    What are you trying to accomplish?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-19 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found