Dermot wrote:
> HI All,
>
> Is anyone familiar with the workings of Config::General?
>
> I am struggling to get my configuration values out of a file.
>
> My config file looks like this:
>
> name myApp
> <model>
> <connect_info>
> dbi:SQLite __HOME__/database.db
> </connect_info>
> </model>
>
>
> When I use Data::Dumper to dump the whole config I see this
>
> 'content' => [
> 'name myApp',
> '<model>',
> '<connect_info>',
> 'dbi:SQLite __HOME__/database.db',
> '</connect_info>',
> '</model>
> ...
> 'DefaultConfig' => {
> 'model' => {
> 'connect_info'
> => {
>
> 'dbi:SQLite' => '__HOME__/database.db'
>
> }
> },
> ...
> 'model' => {
> 'connect_info' => []
> },
>
>
> It's this last item that is returned when I ask for it as
> $config->{'model'}->{'connect_info'} and it' always empty. Below are
> some debug messages I've put in and what the print.
>
> print STDERR Dumper($config->{'model'});
> print STDERR scalar(@{$config->{'model'}->{'connect_info'}}),"\n";
> print STDERR "DSN=$dsn INFO=$config->{'model'}->{'connect_info'}->[0]\n";
> for (@{$config->{'model'}->{'connect_info'}} ) {
> print STDERR "$_ \n";
> }
> #print Dumper($config);
>
>
> $VAR1 = {
> 'connect_info' => []
> };
> Use of uninitialized value in substitution (s///) at
> script/import-tabfile.pl line 22.
> 0
> Use of uninitialized value in concatenation (.) or string at
> script/import-tabfile.pl line 25.
> Use of uninitialized value in concatenation (.) or string at
> script/import-tabfile.pl line 25.
> DSN= INFO=
>
>
> Bit of a long shot I know and a very specific but I can't see anything
> wrong with the file of the way I reference it.
> Any help appreciated.
Hi Dermot.
Does this help?
Rob
use strict;
use warnings;
use Config::General;
my $config = Config::General->new( -ConfigFile => \*DATA);
my %config = $config->getall;
print $config{model}{connect_info}{'dbi:SQLite'};
__DATA__
name myApp
<model>
<connect_info>
dbi:SQLite __HOME__/database.db
</connect_info>
</model>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/