in reply to refrencing a hash

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};

Replies are listed 'Best First'.
Re^2: refrencing a hash
by give_me_donations (Initiate) on Feb 17, 2005 at 01:21 UTC
    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
        $package::config::ERRMSG is just a name. You can access the value associated with that name by simply saying $package::config::ERRMSG from anywhere in any package. But you can't assign a name to another name; that just doesn't make sense.

        The value associated with that name is a reference to a nameless (anonymous) hash stored in memory. Likewise, $foo::bar::package::ERRMSG contains a reference pointing to the exact same hash in memory. To prove it, simply print the value of $ERRMSG in your config package and every package that uses it. You'll see something like:

        HASH(0x1010e180)

        The number is the memory address where the hash is stored, and each copy in each of your packages will have the same number there.

        By the way, please check out the <code> tag for formatting your code so we can read it easily.

        Also see perlref and perldsc.

        What problems are you having with Class::Singleton? Show some code and we'll probably be able to point to what's wrong. Remember to use the <code> ... </code> tags. :)