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

My large perl application suddenly started complaining that the variable %mycode_pegs was not defined. I'm not aware of having made changes to these files recently.

I added %mycode_pegs to a use vars() statement in an attempt to fix this. Although the module no longer complains of the hash being undefined, it no longer seems to be able to access its data.

Here are the tops of the relevant files:

mycode_payment.pm

#!/usr/bin/perl -- use warnings; package mycode_payment; require Exporter; @ISA = qw (Exporter); @EXPORT = qw(@EXPORT_OK); @EXPORT_OK = qw($dbh %form %session); use common qw(%form $dbh %session); use mycode; use mycode_config qw(%config); use mycode_pegs qw(%mycode_pegs); use mycode_create_orders; use mycode_forms; use mycode_includes; use site_config qw(%site_config); use Digest::MD5 qw(md5_hex); use Business::CreditCard; use strict; use vars qw($dbh %form %session %site_config %config %mycode_pegs); use mycode_payment_maxmind;

Lots of subroutines follow, making up the rest of this module.

mycode_payment_maxmind.pm

#!/usr/bin/perl -- use warnings; package mycode_payment; require Exporter; @ISA = qw (Exporter); @EXPORT = qw(@EXPORT_OK); @EXPORT_OK = qw($dbh %form %session); use common qw(%form $dbh %session); use mycode; use mycode_config qw(%config); use mycode_pegs qw(%mycode_pegs); use mycode_create_orders; use mycode_forms; use mycode_includes; use site_config qw(%site_config); use Digest::MD5 qw(md5_hex); use Business::MaxMind::CreditCardFraudDetection; use Business::MaxMind::TelephoneIdentitification; use Business::MaxMind::TelephoneVerification; use strict; use vars qw($dbh %form %session %site_config %config);

Lots of subroutines follow, making up the rest of this module.

mycode_pegs.pm

#!/usr/bin/perl -- use warnings; package mycode_pegs; require Exporter; @ISA = qw (Exporter); @EXPORT = qw(@EXPORT_OK); @EXPORT_OK = qw(%mycode_pegs); use strict; use common qw(%form $dbh %session); use common_config qw(%common_config); use site_config qw(%site_config); use mycode_config qw(%config); use mycode; use mycode_create_orders; use vars qw(%mycode_pegs);

Lots of keys and values of %mycode_pegs are now defined, making up the rest of this module. It is these values that are not accessible in mycode_payment_maxmind.pm any more for some reason.

These problems are happenning under Apache 1.x running mod_perl. The mod_perl startup script uses a lot of these modules too:

use mycode_config qw(%config); use mycode_pegs qw(%mycode_pegs); use mycode_includes(); use email_sellcart(); use mycode(); use mycode_admin(); use mycode_buylist(); use mycode_ccgateways(); use mycode_create_orders(); use mycode_forms(); use mycode_from(); use mycode_lang_ccverify(); use mycode_makemoney(); use mycode_newsletter(); use mycode_pages(); use mycode_payment(); use mycode_productentry(); use mycode_redflag(); use mycode_store(); use mycode_wish(); use mycode_actions_payment(); use mycode_payment_maxmind();

Can anyone suggest why the %mycode_pegs hash is not being exported into mycode_payment_maxmind.pm any more, and what I might be able to do to fix it?

Thank you.

Replies are listed 'Best First'.
Re: Hash no longer being exported/imported between modules
by SuicideJunkie (Vicar) on Aug 27, 2009 at 20:09 UTC

    Since there haven't been any replies yet, I'll post some thoughts:

    Adding use vars to make the error go away sounds like the opposite direction from figuring out what the problem is.

    The first thing to ask, is what has changed since it last worked. Diffs are great if you have them. Tracing the exports and uses and Dumpering to see what point you start to lose the variable could help too.

    You might want to consider having a function that returns a copy of or reference to your %mycode_pegs hash, rather than having it be exported. Just to keep things simple and narrowly scoped, and to make it easy to see when you are declaring it vs defining it vs using it.

Re: Hash no longer being exported/imported between modules
by jethro (Monsignor) on Aug 27, 2009 at 21:34 UTC

    You could check if your package mycode_pegs gets loaded by the other modules correctly. Just dump %INC to a logfile from the other modules and check if it is there with the correct path.

    If it is in %INC, check if you can access the variable %mycode_pegs with its full path, i.e. is %mycode_pegs::mycode_pegs empty as well?