Hi folks, I'm trying to move my debug and validate modules to a seperate package. However, I'm having trouble. I've created a new empty module/package direct from the perldocs and then put my debug routine in. So far, so good.
I then created my program to use it, but I'm having trouble accessing the %_DEBUG hash in main::. The idea is that when I want to use debug, I create my hash, use the module, and it accesses my hash. As you can see, it's not working. I'm assuming that the problems with the syntax I'm using to access %{$package}::_DEBUG. package Trainset::Utils; use strict; use warnings; BEGIN { use Exporter; our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION='0.1'; @ISA=qw{Exporter}; @EXPORT = qw(&debug &validate); @EXPORT_OK = qw(&debug &validate); %EXPORT_TAGS=(); } sub debug { # return debug info my $caller=(caller(1))[3]; my $package=''; print "caller=$caller\n"; ($package,$caller)=split('::',$caller); print "package=$package caller=$caller\n"; print "key=$_\n" foreach (keys %package::_DEBUG); return (defined $package::_DEBUG{$caller}) ? $package::_DEBUG{$caller} : 0; }; 1; #!/usr/bin/perl -w use strict; use lib "."; use Trainset::Utils; our %_DEBUG=(one=>1,mysub=>2); my $resp=debug(); print "resp=$resp\n"; $resp=mysub(); print "resp=$resp\n"; sub mysub () { return debug(); } [EMAIL PROTECTED] trainset]$ ./t main::mysub() called too early to check prototype at ./t line 13. Use of uninitialized value in concatenation (.) or string at Trainset/Utils.pm line 20. caller= Use of uninitialized value in split at Trainset/Utils.pm line 21. Use of uninitialized value in concatenation (.) or string at Trainset/Utils.pm line 22. Use of uninitialized value in concatenation (.) or string at Trainset/Utils.pm line 22. package= caller= Use of uninitialized value in hash element at Trainset/Utils.pm line 24. resp=0 caller=main::mysub package=main caller=mysub resp=0 [EMAIL PROTECTED] trainset]$ -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>