in reply to Apache::Registry and main package

Avoid accessing variables in other packages from within a module like the plague. Pass the variable that you want to use in the subroutine as an argument to the subroutine. Or if you want to get fancy, instantiate an object. Here's the simple way:

AlCommon::ApplicationAbout( %ApplicationDetails ); # ... package AlCommon; sub ApplicationAbout { my %details = @_; foreach my $AboutItem (qw(Name Version Comments)) { print "$AboutItem = $details{$AboutItem}\n"; } }
--
edan

Replies are listed 'Best First'.
Re^2: Apache::Registry and main package
by allyc (Scribe) on Oct 31, 2004 at 00:09 UTC

    Thanks guys. Advice taken! I am very very new to writing modules, and I want to try and make them mod_perl compatible which should be fun.

    I will pass the hash to the function as I normally would however what would be the best way to share a hash between the Module and the main script?

    If I declare it in the module and then return a Hash Ref to the calling script?

    I am guessing the same applies if I want to share a Database Handle between them? Just get one of them to pass a reference across?

    Any advice would be greatly appreciated!

    Al