Please bottom post....

> my openconf function contains:
> 
> sub openconf {
>    my $pkg = shift;
>    my $self = bless([EMAIL PROTECTED],$pkg);
>    open(...
>    ....
>    return($self);
> }
> 
> I have "my @config;" set at the beggining of the module
> 

As Lee pointed out it would be easier to help if we could see some real
code. 

However your last sentence is likely the first problem, you are making
@config lexical and file scoped, which means there is only one, so you
are in effect creating a singleton to access into.  Each time you call
your constructor you are really just reblessing a reference to the same
variable. I suspect you are just appending all of the values from one
config onto the other, that or you are clobbering all of them each time
you read the file, either way you are only going to end up with one set
of config values, which doesn't appear to be what you want.

I would suggest moving the my @config into the scope of the constructor,
(yet another case of the declare your variables when you use them rather
than at the top syndrome).  Of course since this is a config object that
appears to be accessible by key name rather than numerical index you
probably want to switch @config to %config, but that is a design
decision....

You may want to read through the OOP documentation provided with the
perldocs, specifically,

perldoc perlboot

Like I said, don't rewrite the wheel....

http://danconia.org

> -------------------------------------
> This mail is from: <[EMAIL PROTECTED]>
> -------------------------------------
> 
> On Wed, 12 May 2004, Wiggins d Anconia wrote:
> 
> > > Hi,
> > > I'm trying to create library that can open many config files. For
> > > examlpe, I have cfg1.conf and cfg2.conf. My lib is getting information
> > > from those files and store it into an array. If I do:
> > >
> > > my $cfg1 = My::Lib->openconf("cfg1.conf");
> > > my $cfg2 = My::Lib->openconf("cfg2.conf");
> > >
> > > print $cfg1->param("someparam");
> > > print $cfg2->param("someparam");
> > >
> > > it prints two times the param from second conf file. Any ideas or
I wasn't
> > > clear enough ?:")
> > > Btw sorry for my bad english
> > >
> >
> > We will probably need to see your My::Lib, specifically the 'openconf'
> > and 'param' methods to help...
> >
> > Consider using a configuration implementation from CPAN (there are lots)
> > instead of growing your own.
> >
> > http://danconia.org
> >
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to