config::iniffiles.

N

Nikhil

Hi All,

I have a doubt with Config::Inifiles module,
Basically what I want my ini file to like this..
[Services]
server1 = "service1","service2","service3"
and then should be able to load this server1 onto an array such that
array should consists of @array = ("service1","service2","service3");
then I should be able to individually process the array elements..
if it is possible, can someone please tell me how..

Regards,
Nikhil
 
F

Fabian Pilkowski

* Nikhil said:
Hi All,

I have a doubt with Config::Inifiles module,
Basically what I want my ini file to like this..
[Services]
server1 = "service1","service2","service3"

AFAIR, this is no valid entry for any ini-file. You have to out the
double quotes around the complete value like this:

server1="service1,service2,service3"
and then should be able to load this server1 onto an array such that
array should consists of @array = ("service1","service2","service3");

Well, after processing the ini-file as describes in the documentation
shipped with Config::IniFiles (with "F" instead of "f", case matters)
you can use split() to put your values into an array.

my @array = split /,/, $value;

regards,
fabian
 
R

Randy Kobes

Nikhil said:
Hi All,

I have a doubt with Config::Inifiles module, Basically what I want my
ini file to like this..
[Services] server1 ="service1","service2","service3"
and then should be able to load this server1 onto an array such that
array should consists of @array = ("service1","service2","service3");
then I should be able to individually process the array elements.. if
it is possible, can someone please tell me how..

Regards, Nikhil

You could use a syntax like this in your config file:
======================================================
[S1]

colors = <<EOL
red
green
blue
EOL
======================================================
and then read in the values directly as an array:
======================================================
#!/usr/bin/perl
use strict;
use warnings;
use Config::IniFiles;
my $config = 'ex.conf';
my $cfg = Config::IniFiles->new(-file => $config);
my @colors = $cfg->val('S1', 'colors');
foreach my $color(@colors) {
print "Found $color\n";
}
===================================================
 
D

Dave Weaver

I have a doubt with Config::Inifiles module,
Basically what I want my ini file to like this..
[Services]
server1 = "service1","service2","service3"
and then should be able to load this server1 onto an array such that
array should consists of @array = ("service1","service2","service3");

Perhaps using Config::Simple would be, erm, simpler?

#!/usr/bin/perl
use strict;
use warnings;

use Config::Simple;

my $config = Config::Simple->new( "/tmp/test.ini" )
or die Config::Simple->error();

my $services = $config->param( -block => 'Services' )->{ server1 };

print "$_\n" for @$services;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,081
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top