give_me_donations has asked for the wisdom of the Perl Monks concerning the following question:

I have two modules one module has this
package::config; use exporter; use vars qw (@isa @export @export_ok %export_tags $version); %EXPORT_TAGS = ( sms => [ qw( $SMS_DISABLE_DL %ERRMSG ) ], ); @EXPORT_OK = ( @{ $EXPORT_TAGS{'sms'} }, ); use vars qw( %ERRMSG ); $ERRMSG{123} = "some string error1"; $ERRMSG{345} = "some string error2";
somewhere else in my 2nd module I have this
use package::config qw(:sms );

but when I go to mydomain.com/perl-status?package::caller I see it's making a copy of ERRMSG hash I'm trying to use Class::Singleton but I can't figure out, I'll appreciate any help or hints.....what I want to do is when I call the ERRMSG in some other package I want to see it refrenced from it's original package and not make a copy

20050217 Janitored by Corion: Added code tags around code

Replies are listed 'Best First'.
Re: refrencing a hash
by friedo (Prior) on Feb 17, 2005 at 01:15 UTC
    I don't see how your code could have possibly compiled in the first place, as "exporter" is not a valid module name. Perl packages and variables are case-sensitive. @ISA, @EXPORT, @EXPORT_OK and %EXPORT_TAGS must be upper-case in order for Exporter to work properly. I suspect this is perhaps not a direct copy-and-paste from your real code?

    In any event, your second package is getting a copy of package::config's %ERRMSG because the implicit import does something akin to this:

    %package::caller::ERRMSG = %package::config::ERRMSG;

    If you want a reference to the original hash (no copy) then you can set it up as a reference in your config module.

    package Config; use base 'Exporter'; our $ERRMSG = { 123 => 'Some string error1', 456 => 'Some string error2' }; our @EXPORT_OK = qw($ERRMSG); our %EXPORT_TAGS = ( sms => [qw($ERRMSG)] ); package Foo; use Config qw(:sms); print $ERRMSG->{123}; print $ERRMSG->{456};
      hey thanks a lot for replying, yeah I didn't copy and paste i was gonna type it all out but then I changed my mind, well what I really wanna do is use the Class::Singleton module since I'm struggling with it for last 2 days and haven't gotten anywhere :( and there's a lot of code I would have to make changes to ....the ERRMSG has around 2000 errors :( I'll appreciate any help...
        I did what you expalined but still this is what I see on perl-status Data Dump of foo::bar::package::ERRMSG SCALAR $foo::bar::package::ERRMSG = { 'CUSTLINK_CREATESESSION_506' => 'We did not recognize your member name or password. Please re-enter your member name and password. (Error 506)', 'CUSTLINK_GETVALUE_506' => 'We did not recognize your member name or password. Please re-enter your member name and password. (Error 506)', 'CUSTLINK_LOOKUP_506' => 'We did not recognize your member name or password. Please re-enter your member name and password. (Error 506)' }; whereas I wanna show this ($foo::bar::package::ERRMSG = ) saying (package::config::ERRMSG) thanks in advnace