Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^23: global var

by tultalk (Monk)
on Apr 23, 2017 at 16:31 UTC ( [id://1188695]=note: print w/replies, xml ) Need Help??


in reply to Re^22: global var
in thread global var

Fundamental question

module_1.pm Initializes variable A to 100. Code changes variable A to 300.

Module_2.cgi uses module_1 but since module_1 is already loaded, it is not loaded again and variable A should be visible to Module_2 as 300.

Is this correct?

Replies are listed 'Best First'.
Re^24: global var
by poj (Abbot) on Apr 23, 2017 at 20:04 UTC

    If this is what you mean, try it

    package module_1; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw($A); our $A = 100; 1;
    #/usr/bin/perl # script_1.cgi use strict; use CGI ':standard'; use lib 'path/to/module'; use module_1 qw($A); $A = 300; print header,start_html, h1("\$A = $A"), a( {href=>"script_2.cgi"}, "script_2"), end_html;
    #/usr/bin/perl # script_2.cgi use strict; use CGI ':standard'; use lib 'path/to/module'; use module_1 qw($A); print header,start_html, h1("\$A = $A"), a( {href=>"script_1.cgi"} ,"script_1"), end_html;
    poj

      Exactly

      module_1 initializes $A to 100. script_1 changes #A to 300 and prints it. script_2 loads module_1 and prints $A as 100, the value initialized in module_1.

      This is my exact problem.

        This is my exact problem.

        Going back to your post Re^15: global var I think I now understand. You are accessing $manageusers::LoggedOn_user_id from a different script (update_table.cgi ?) from the one that set the value which was presumably manage_users.cgi. As you found that doesn't work.

        One solution would be retrieve it directly from the CGI::Session object.

        my $dbh = manageusers::OpenConnection(); warn("update_tables.cgi after open connection"); # Dispatch to proper action based on user selection my $count = 0; my $query = new CGI; my $cgiURL = CGI::url(); my $action = lc ($query->param('action')); ## changes ## # my $userid_1 = 0; my $session = CGI::Session->load( "driver:MySQL", $query, { Handle => $dbh } ); my $userid_1 = $session->param("user_id");
        poj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-23 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found