Perrin Harkins wrote:

> Andreas Schiffler wrote:
> >
> > Hi,
> >
> > I seem to have an odd problem with variable setup and use. The platform
> > is apache/mod_perl as per LinuxMandrake 7.1.
> >
> > Here is the setup:
> >
> > A) I have a configuration.pm with variable declarations and no "use
> > strict" similar to this:
> >
> > ...
> > @array=()
> > ...
> > %hash=()
> > ...
> >
> > B) Then I have a library of common routines that make use of these
> > variables. These include routines to fill these variables with data.
> >
> > sub fill_array();
> > sub fill_hash();
> >
> > C) Now in startup.pl is "use" both packages and call the fill_xyz()
> > routines.
> >
> > D) In the mod_perl scripts (the guts of these scripts is again in a
> > package that gets called by a wrapper .pl script) I "use" both packages
> > and make use of the data with $value=$configuration::array[] and
> > $value=$configuration::hash{} ... just reading their values.
> >
> > The Problem:
> > The array is filled. The hash is empty.
> >
> > Any ideas? Workarounds? Tests?
>
> You didn't include enough code here for me to see what you're doing
> wrong, but your variable assignments look fishy.  Here's a sample of how
> to do it:
>

Well, I did ... you are close though.

>
> package SiteConfig;
> %hash  = (
>            'name'  => 'value',
>            'name2' => 'value2',
>          );
>

I use:

package SiteConfig;
%hash=();

and define a fill_hash() routine in another package:

package common;
use SiteConfig;
sub fill_hash() {
%SiteConfig::hash = ('name' => 'value',);

>
> # in startup.pl
> use SiteConfig ();

I do a:

use SiteConfig();
use common;
common->fill_hash();

>
>
> # in your module
> my $value2      = $SiteConfig::hash{'name2'};
> my $entire_hash = %SiteConfig::hash;
> my $hash_ref    = \%SiteConfig::hash;
>
>

Same here with:

use SiteConfig();
use common;
my $value = $SiteConfig>>hash{'name');


Problem: The hash is not defined! (The same for an array works fine.)

Ciao
Andreas

--
|  Andreas Schiffler                    [EMAIL PROTECTED]  |
|  Senior Systems Engineer    -    Deskplayer Inc., Buffalo  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada  |
|  +1-905-371-3652 (private)  -  +1-905-371-8834 (work/fax)  |


Reply via email to