Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Sharing Global variables between scripts

by gjb (Vicar)
on Apr 16, 2004 at 21:52 UTC ( #345885=note: print w/ replies, xml ) Need Help??


in reply to Sharing Global variables between scripts

Given the other responses I may be way off, but my impression is that you want to accomplish the following:

  1. the values of the variables $project et al. are set when Dispatcher.cgi.pl is executed;
  2. when TAZ.pl is executed, you want to use those values.
Unfortunately this is not possible in a trivial way since once the execution of Dispatcher.cgi.pl is done, the values of all variables are gone without a trace.

What you want to accomplish is the notion of a session, i.e. several interactions with a webserver that maintains the state between those interactions.

The simplest way to do this is to embed the values of the variables you want to preserve in the HTML code the first script generates using hidden input fields. This is quick & dirty, hard to maintain and unsafe.

Another way is to store those values in cookies on the client with all drawbacks associated with the use of cookies.

Yet another is to use some session framework such as CGI::Application which is quite mature but might be intimidating at first.

The "right thing to do" depends strongly on the type of job you've at your hands.

Just my 2 cents, -gjb-


Comment on Re: Sharing Global variables between scripts
Select or Download Code
Re: Re: Sharing Global variables between scripts
by TASdvlper (Monk) on Apr 16, 2004 at 22:24 UTC
    thanks.

    Well, TAZ.pl is called in the middle of Dispatcher.cgi.pl. So, basically, when TAZ.pl is running so is Dispatcher. Once, TAZ.pl exits, it goes back and finishes the rest of the Dispatcher code. Now, saying that, wouldn't the variables still be around ?

      Thanks to a short CB exchange I now see what you have in mind. You're using a system call to execute TAZ.pl from within Dispatcher.cgi.pl.

      So yes, the variables still exist, but unfortunately you can't access them from within

      TAZ.pl</ocde> since both scripts are running in their own Perl interpr +eter and don't share anything.</p> <p>The best thing to do I guess is to transform <code>TAZ.pl
      into a function and call that from within Dispatcher.cgi.pl by directly including it in that file. The advantage is that you can make $project et al. parameters of that function which is much cleaner.

      You can also put that function into a module and load it with use.

      Hope this helps, -gjb-

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://345885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-09-23 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls