Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: global var

by poj (Abbot)
on Apr 06, 2017 at 18:01 UTC ( #1187325=note: print w/replies, xml ) Need Help??


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

In your original post you wrote 'I have global var in main unit:' and 'In another unit I have: use manageusers;'

What do you mean by 'unit' ?. Do you have the same variable name declared in both the cgi script and the manageuser module something like this

# cgi script use strict; our $LoggedOn_user_id = 0; # # # use manageusers qw($LoggedOn_user_id); print $LoggedOn_user_id;
# package package manageusers; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( $LoggedOn_user_id ); our $LoggedOn_user_id = 123; 1;

The code prints 0 not 123

poj

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

    our $LoggedOn_user_id = 0;

    Initializing variable. Later modified with data I want to share to other unit,

    Unit? Module? same difference, is it not?

    No on the var names being duplicated. Did multiple searches. Only one declaration with values loaded at different locations in program.

    This whole program is for a landlord association. Member logs on. Drill down to their status which is loaded into dataset displayed on form (using their unique id passed with $LoggedOn_user_id to the unit generating/displaying dataset. Display includes the number of tenants associated with this member. Next step is to drill down with click on that number to pull up another dataset of all tenants to display.

    When I manually set value in calling unit:

    #$userid_1 = manageusers::LoggedOn_user_id; #$userid_1 = $manageusers::LoggedOn_user_id; #$userid_1 = $LoggedOn_user_id; $userid_1 = 428;

    It of course works fine.

    Have another global

    $adminaccess = ($username1 eq "admin");

    To activate/inactivate menu items depending on login status using javascript in webpage. Logout succeeded form into iFrame deactivates menu through messaging.

    <script type="text/javascript"> var adminflag = $manageusers::adminaccess; </script>

    Passing variables not new.

      Unit? Module? same difference, is it not?

      Sorry to be so pedantic but it may be relevant to solving your problem. When you said in your post

      I have global var in main unit:
      @EXPORT = qw( $LoggedOn_user_id $VERSION = '0.0.1'; } our $LoggedOn_user_id;
      do you mean that code is in the 'main' part of package manageusers. At the top maybe before the subroutines declaration ?

      poj
Re^6: global var
by tultalk (Monk) on Apr 06, 2017 at 23:31 UTC

    Export and calls look the same but I keep getting:

    Software error:

    "LoggedOn_user_id" 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.
    

    Do not understand. Not this way for others. Something unique about this.

      In a former post here Re^4: global var you had this 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
      

      and your @EXPORT_OK in manageusers was

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

      I hope you understand the cause of that error now in that $GetLoggedOnId and &GetLoggedOnId are different things.

      You now have the error

      "LoggedOn_user_id" is not exported by the manageusers module

      The questions that raises is

      Have you changed $GetLoggedOnId to LoggedOn_user_id and if so have you amended both the @EXPORT_OK in manageusers and the use manageusers qw() statement in update_tables-development.cgi ?

      As the error appears on line 30 perhaps you could post those first 30 lines of that script. Check the names carefully as in another post Re^6: global var you mentioned a function call &GetLoggedOn_user_id which is different again.

      poj

      Why does your code ask "managerusers" module to exports a "LoggedOn_user_id" function?

        Answer his and one above.

        Manageusers is the "main" unit in the sense that everything get funneled back to that unit for accessing database tables and all the login /logout functions. I consider it the "main" unit to which manage_users.cgi interfaces between thr web pages and the guts of the program.

        The loggedonuser the ID of the user far accessing various other pieces of data such a database records "owned" by the user.

        The change from LoggedOn_user_id to GetLoggedOn... and back again was a result of trying an exported function result to pass the id vs a scalar variable. Neither worked.

        Other functions/.scalars are exported just fine. Not this one!!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-06-20 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (95 votes). Check out past polls.

    Notices?