http://www.perlmonks.org?node_id=1187195


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

What you are trying to import is not a function.

- use manageusers qw(LoggedOn_user_id); + use manageusers qw($LoggedOn_user_id);
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^6: global var
by tultalk (Monk) on Apr 06, 2017 at 12:32 UTC

    Hi:

    Read it was not necessary there. Tried both ways. With $ returns:

    Software error:

    "$GetLoggedOnId" is not exported by the manageusers module
    Can't continue after import errors at update_tables-development.cgi line 30
    BEGIN failed--compilation aborted at update_tables-development.cgi line 30.
    

    Padre also says the function in question is not exported by manageusers.

    our @EXPORT_OK = qw( &OpenConnection &OpenSession &ProcessLoginRequest &ProcessLostDataRequest &LoginUser &GetLoggedOnId <<<<-------------------

    Not posting whole thing to avoid severe criticism from some commenters . etc.

    I have many exported other functions and variables and they all work fine. Some are exported, some are not. OpenConnection is exported works fine. CloseConnection not exported and works fine. Both called manageusers::OpenConnection(); and manageusers::CloseConnection();

    #--------------------------------------------------------------------- +---------- # 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; } #--------------------------------------------------------------------- +---------- # FUNCTION: CloseConnection # DESCRIPTION: Disconnect from the MySQL database #--------------------------------------------------------------------- +---------- sub CloseConnection { my $localdbh = @_; my $localtimenow = localtime(Now()); if ($localdbh){ $localdbh->disconnect(); } elsif ($dbh) { $dbh->disconnect(); } warn("Close Connection -just before exit Current Time: '$loca +ltimenow'"); # exit(0); }
      Not posting whole thing to avoid severe criticism from some commenters . etc.

      If you avoid criticism, you avoid learning. If you avoid learning, all you ask is to help you out of a fix. I might do that for some time, but not very long. I'm not going to help you over the road everytime you want to go to the bakery.

      That said, in no post of you in this thread which contains that purported BEGIN block from manageusers does this variable show up. Except in this last one. So things are changing, but I won't play a pointless shell game.

      You need not import a variable from another package to use it. You can use it also fully qualified in your code, in this case as $manageusers::GetLoggedOnId - if this variable really exists in that package (who knows? It looks like you don't either). If it doesn't exist there and you use it anyways, it will be created. Will that be of any use? I don't know and won't guess.

      You could, instead of posting the entire fluff here, stick it onto tultalk's scratchpad. Eventually somebody will look over it and tell you what's wrong.

      Padre also says the function in question is not exported by manageusers.

      • use manageusers qw(GetLoggedOnId) imports a function
      • use manageusers qw($GetLoggedOnId) imports a scalar variable
      • use manageusers qw(%GetLoggedOnId) imports a hash variable
      • ...
      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'