Hello All,

I'm trying to declare global variables between scripts and am having some problems.

In a script called Dispatcher.cgi.pl I declare a package called Dispatcher (see below):

package DispatchParser; use strict; use warnings; use lib '../modules/perl'; use lib '../modules/db'; use CommonFunctions; use CGI; use DataBaseActions; use POSIX ":sys_wait_h"; use Data::Dumper; use CGI::Carp qw(fatalsToBrowser set_message); my $q = new CGI; my $username = &GetUser(); my @ValArray; our $project = $q->param('project'); our $release = $q->param('release'); our $globalpid; # defined later in script ... rest of code ...
Basically, I'm trying to expose $project, $release and $globalpid as global variable so other modules/script can use them.

But, in a script called TAZ.pl, I'm trying to use those variables and it's giving me a error message:

Undefined subroutine &DispatchParser::GetUser called at ../exe/TAZ.pl line 33.

Where the function GetUser is defined in the module CommonFunctions (see below).

I'm a little puzzled as to what is going on.

TAZ.pl snippet

use strict; use warnings; use lib '../modules/perl'; use lib '../modules/db'; use lib '../tsr'; use CommonFunctions; use POSIX ":sys_wait_h"; use Date::Manip; use Time_Diff; use LogIt; use DataBaseActions; use IOrate; use emailinfo; package DispatchParser; our ($project, $release, $globalpid); print "project = $project<br>\n"; my $username = &GetUser(); ### this is line 33
I'm guessing it has something to do with the order I include the package ?

Any help would be greatly appreciated.

I'm calling TAZ.pl from within Dispatcher.cgi.pl.

my $cmd = "/msg/spgear/tools/bin/perl ../exe/TAZ.pl \\\"$valhash{'agen +da'}\\\" now"; system("$cmd");
When TAZ.pl completes it goes back to Dispatcher.cgi.pl and then that code completes.

In reply to Sharing Global variables between scripts by TASdvlper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.