SPUG: Confusing behaivior with exported variables

Mark Mertel mark.mertel at yahoo.com
Fri Mar 20 13:36:48 PDT 2009

Not sure, and this may be a stupid answer, but could it be you didn't tie the second variable? Its hard for me to debug out of context.

Mark Mertel
mark.mertel at yahoo.com

From: Peter Darley <pdarley at kinesis-cem.com>
To: spug-list at pm.org
Sent: Friday, March 20, 2009 12:35:40 PM
Subject: SPUG: Confusing behaivior with exported variables

                It’s been a long time since I’ve bugged y’all with a stupid question, but I’ve got a new one so I’m hoping someone can help me out.
                The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it’s self.  I have two modules, one on a machine at work and one on a machine at home.  Both are doing something that looks super similar to me.
                At work I have: 
package Neo::Web;
use ...
use CGI qw/:standard/;
use CGI::Cookie;
use Apache::DBI;
use Apache::Session::Postgres;
use Data::Dumper;
                use Exporter   ();
                @ISA         = qw(Exporter);
                @EXPORT      = qw(%Session $SessionID 
                                                  &TieSession &UntieSession ... );
sub TieSession
                tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0};
                $SessionID = $Session{_session_id};
                The scripts using this package can get at %Session, and this module can get at %Session.  They are the same variable and have the same contents.
                At home I have:
package Darley::Supers;
use ... ;
use Data::Dumper;
                my (%CurrentUser);
        use Exporter   ();
        @ISA         = qw(Exporter);
        @EXPORT      = qw(%CurrentUser
                                  &Power &Challenge &GetUser &GetOrg &GetCity);
sub SetCurrentOrgSetting
                my (%Args) = @_;
                # Args: Setting = Setting to store
                #             Value = Value to store
                StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value});
                $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value};
                return 1;
                And the script using this module can get at %CurrentUser, but when this package uses it, it’s empty.  I can’t figure out why the exported hash is the same in the first example, but has two different values in the second.
Thanks for any help,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090320/31b306d0/attachment-0001.html>

More information about the spug-list mailing list