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

two days ago and one day ago both answer this

Now regarding Re^13: global var this is the output of your posted bug report

$ perl -I. tultalk 428

It shows no bug , no problem , no errors, no warnings

The code you posted doesn't reproduce the problem you want to solve in your real program

If your real program were the same, then it should have no problem

But then you say your real program does have a problem

This is not productive way to solve problems

Replies are listed 'Best First'.
Re^15: global var
by tultalk (Monk) on Apr 11, 2017 at 14:23 UTC

    You pose a dilemma here. Short and sweet, no error. This part of code shows 0 or undefiend at <-------------------------------

    #! /usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use diagnostics -verbose; use warnings; use CGI; use CGI qw(:standard escapeHTML); use CGI qw/:standard/; use lib qw(/usr/local/apache/lib/perl); use vars qw($dataupdatemessage $dataupdatefilemessage ); local ($CGI::DISABLE_UPLOADS, $CGI::POST_MAX); $CGI::DISABLE_UPLOADS = 0; # enable uploads Disable uploads $CGI::POST_MAX = 32 * 1024; # limit posts to 32K max<------NEED + TO LOOK AT THIS LIMIT use lib qw(/home/jalamior/www/httpsdocs/cgi-bin/lib/perl); #use lib qw(/srv/www/cgi-bin/lib/perl); use manageusers qw($LoggedOn_user_id); #Error Handling BEGIN { require 5.004; use CGI::Carp qw(fatalsToBrowser carpout); my $logfile = '/home/jalamior/public_html/httpsdocs/cgi-bin/logs/err +orLog/errorFile.log'; # open LOG, ">>$logfile" or die "Couldn't append to $logfile: $!\n"; # carpout(\*LOG); }; warn("Entered update_tables.cgi"); warn("update_tables.cgi before open connection"); #--------------------------------------------------------------------- +--------------------------- my $htmlMemberDownloadHeader='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML +4.01 Transitional//EN"><html><head><title>Member Data Download Form</ +title>'; my $htmlMemberDataFeedbackHeader='<!DOCTYPE HTML PUBLIC "-//W3C//DTD H +TML 4.01 Transitional//EN"><html><head><title>Member Data Update Feed +back Form</title>'; my $htmlTenantListingFormHeader='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HT +ML 4.01 Transitional//EN"><html><head><title>Tenant Listing Form</tit +le>'; my $htmlheader2 = '<meta https-equiv="Content-Type" content="text/html +;charset=iso-8859-1">'; my $htmlheader3 = '<link rel="StyleSheet" href="/graphics/jala_styles. +css" type="text/css">'; 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')); my $userid_1 = 0; ############################################################### $userid_1 = $manageusers::LoggedOn_user_id; <------------------------- +-------- #$userid_1 = 110;

    The other side of the interface boundary:

    package manageusers; use strict; use diagnostics -verbose; use warnings; use CGI; #use Carp::Always; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI qw(:standard escapeHTML); use CGI qw/:standard/; use Data::Dumper; use Digest::MD5 qw(md5_hex); #use DB_File; # persistent hash database use CGI::Session; use CGI::Cookie; #use vars qw($session_cookie1 $session_cookie2 $login_timeout); #use vars qw($session); use Mail::Sendmail; use Time::HiRes qw(usleep); use Time::Local; BEGIN { require Exporter; use vars qw($VERSION @ISA @EXPORT_OK); use DBI; # use vars qw(@ISA @EXPORT_OK); # $ENV{DBI_TRACE}=1; # $ENV{PERL_DBI_DEBUG}=1; @ISA = qw(Exporter); # exported functions our @EXPORT_OK = qw( &OpenConnection &OpenSession &ProcessLoginRequest &ProcessLostDataRequest &LoginUser &decodeEncryptedPassName &UpdateUserData &GetUserLostData &LogoutUser &GetUserSessionCookie &CheckForAuthorizedUser &Expires $LoggedOn_user_id $attempts $adminaccess &Now &CheckValidLoginChar &CheckValidEmailChar &print_md5_javascript); $VERSION = '0.0.1'; }

    Exports the variable $LoggedOn_user_id

    The error reported is that $LoggedOn_user_id is not exported by manageusrs.

    The short test program does not display that error.

    In my program on the defining side of the interface boundary, I declare our $LoggedOn_user_id = 0; so there clearly should be something to export.

    And later I populate the variable with the desired data

    my $username1 = $session->param("user_id"); warn("username1 : '$username1'"); $LoggedOn_user_id = $username1; warn("Already logged on LoggedOn_user_id : '$LoggedOn_user_id'");

    And at that point, the desired information is in the variable.

      IN the code that does show that $LoggedOn_user_id is not exported by manageusrs. put this in right after your use manageusers qw($LoggedOn_user_id); statement

      { use strict; use warnings; my %wanted; $wanted{manageusers}=1; for my $inc (@INC) { opendir (my $dh,$inc) || warn "Can't opendir $inc: $!"; while (my $file=readdir $dh) { if ($file=~m/(.*)[.]pm$/) { if ($wanted{$1}) { warn 'found:'.$inc.'/'.$file; } } } closedir $dh; } }
      and see what your error log says. Be careful to cut and past all of that code, right click on download and select save file as and cut it all from that file you downloaded. Then do it in your sample program above too, and compare the warnings you get from both, remember order in the error log matters! Cut and paste the warnings from both the sample and the real program back here.

      and saying And later I populate the variable with the desired data is easy, proving it is not as easy. So cut and paste ALL of manageusers::OpenConnection() and ALL of every subroutine it calls to prove that you do set $manageusers::LoggedOn_user_id properly every time and dont set it back to zero somewhere else.

        Test Program Error Log

        Can' find the log Padre file

        Real Program Error log:

        found:/home/jalamior/www/httpsdocs/cgi-bin/lib/perl/manageusers.pm at update_tables-development.cgi line 41. Tue Apr 11 11:26:22 2017 update_tables-development.cgi: found:/home/jalamior/www/httpsdocs/cgi-bin/lib/perl/manageusers.pm at update_tables-development.cgi line 41. Can't opendir /usr/local/apache/lib/perl: No such file or directory at update_tables-development.cgi line 38. Tue Apr 11 11:26:22 2017 update_tables-development.cgi: Can't opendir /usr/local/apache/lib/perl: No such file or directory at update_tables-development.cgi line 38.

        Line 30 use manageusers qw($LoggedOn_user_id); { use strict; use warnings; my %wanted; $wanted{manageusers}=1; for my $inc (@INC) { opendir (my $dh,$inc) || warn "Can't opendir $inc: $!"; while (my $file=readdir $dh) { if ($file=~m/(.*)[.]pm$/) { if ($wanted{$1}) { warn 'found:'.$inc.'/'.$file; } } } closedir $dh; } }

        You say: and saying And later I populate the variable with the desired data is easy, proving it is not as easy. So cut and paste ALL of manageusers::OpenConnection() and ALL of every subroutine it calls to prove that you do set $manageusers::LoggedOn_user_id properly every time and dont set it back to zero somewhere else.

        I don't understand the question. Search all fdiles on manageusers::OpenConnection(); yields 10 hits.

        manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection(); manageusers::OpenConnection();

        They all call the same function

        #--------------------------------------------------------------------- +---------- # Database Conection Functions #--------------------------------------------------------------------- +---------- # FUNCTION: OpenConnection() # DESCRIPTION: Connect to the MySQL database #--------------------------------------------------------------------- +---------- sub OpenConnection { my $localtimenow = localtime(Now()); $dbh = DBI->connect($dsn,$sql_username,$sql_password) or ErrorMessage("Could not connect to the database."); warn("Open Connection-JustBefore returning database handle: '$dbh' + Current Time: '$localtimenow'"); return $dbh; }

        You say: prove that you do set $manageusers::LoggedOn_user_id properly every time and dont set it back to zero somewhere else

        It is oly populated at two places. For a new logged on user it gets the id from the session table. For an already logged on user (cookie expires 7 days) it get the ID from the session table based on the SID lookup.

        New login warn("Hash evaluation succeded - $passhash = $passhash1 : $sessiondata +2 = $sessiondata2md5p"); my $timein = time(); $session->param('user_id',$uid); $session->param('username',$username); $session->param('forename', $forename); $session->param('lastname', $lastname); $session->param('timein', $timein); $session->param('timeout', 0); $session->param('attempts',0); $session->param('isloggedin',1); $session->expires('+7d'); $LoggedOn_user_id = $uid; #$session->param("user_id");
        Already logged on if ($status == 1) { warn("Process Login returning after confirmed already logged in: s +tatus: '$status' sessionname: '$sessionname' SID: '$sid'"); my $username1 = $session->param("user_id"); warn("username1 : '$username1'"); $LoggedOn_user_id = $username1; warn("Already logged on LoggedOn_user_id : '$LoggedOn_user_id'");

        This is how you write that shorter and better

        use WHATEVER(); ## no imports, repeat for all failing modules BEGIN{warn join "\n" , %INC, " " } ## log which files were loaded

      This part of code shows 0 or undefiend at ...

      No it doesnt

      This is the same as before, you post a fragment of code that does not compile, does not run, does not show the problem

      Maybe it shows the problem on your machine, where the code is complete and compiles and runs,

      but over here on my machine it shows that you posted incomplete code which cannot help you fix your problem

      huck guesses that you're loading the wrong .pm file but thats too generous on his part

      The problem is you dont want to do what is required to solve the problem, which is keep deleting parts of code which have nothing to do with the problem, until you're left with a short piece of code which does reproduce the problem

      But you keep posting fragments and hoping that will help you solve it

      Thats a weird way to ask for help, here is a joke for that

      Q: I'm hungry but there is no food in the refrigerator?
      A: I went shopping the refrigerator is overfull, there is cheese, apples.....
      Q: I looked again, all I found was a bowl of water
      A: Ok show me where you looked
      Q: Here
      A: Thats the toilet bowl in the bathroom, the refrigerator is in the kitchen, follow me
      Q: but the sink is over here next to the water bowl
      A: Thats the bathroom sink not the kitchen sink, kitchen is over here
      Q: but the big sink is over here
      A: Thats the bathtub in the bathroom, kitchen is over here
      Q: I can see myself in the kitchen window
      A: Thats the bathroom mirror, the kitchen window is see through
      Q: but look at all these nice kitchen floor tiles
      A: those are bathroom floor tiles because they're in the bathroom
      Q: but look at this nice kitchen towel
      A: if its in the bathroom its a bathroom towel
      Q: I'm talking about the white paper towel
      A: thats toilet paper paper towels are thicker
      Q: but look at all these little scrub brushes arent they cute
      A: yes the tooth brushes do look cute in the bathroom, they would be weird in the kichen
      Q: ok mom lets eat