In <> Vito Corleone <> writes:
>Hi,
>I downloaded a module that need me to input the value in very confusing
>way. For example:
>$m = Module::->new(
> { 'servers' => [ "192.168.1.0:5500", "192.168.1.1:5500" ],
> 'debug' => 0 } );
>You put the list of your servers IP and port number into servers. I put
>my servers list in config file. It looks like this:
>use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500';
>And then when I load the module, I do:
>my @servers = split(" ", SERVERS);
>$m = Module::->new(
> { 'servers' => \@servers,
> 'debug' => 0 } );
>So far so good. But you can also load the module this way.
>$m = Module::->new(
> { 'servers' => [ "192.168.1.0:5500", ["192.168.1.1:5500", 3] ],
> 'debug' => 0 } );
>Besides IP and port number, it also takes the value of the server (ie:
>3). I want to make my config file looks like:
>use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500,3';
>But I don't know how can I pass these values to the module. Or is there
>any better way to keep these values in config file? Please help, and
>thanks in advance.
What Anno posted is right, I'm sure, but the code below may be
easier to follow.
# untested
my @servers;
for my $info (split ' ', SERVERS) {
# $info is either of the form ip

ort" or "ip

ort,num"
my ($ip_port, $num) = split /,/, $info;
if ($num) {
# $info is of the form "ip

ort,num"
push @servers, [$ip_port, $num];
}
else {
# info is of the form "ip

ort"
push @servers, $info;
}
}
my $m = Module::->new( { 'servers' => \@servers,
'debug' => 0 } );
__END__
Makes sense?
Karl
--
Sent from a spam-bucket account; I check it once in a blue moon. If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.