Just choose a delimiter and split the values after you read them. What delimiter to use depends on the characters allowed in the values, but most of the time comma is good enough. So assuming the INI contains:
you'd just need to do something like:[path] files=foo.txt,bar.txt,baz.csv
You might do the splitting inside the forValue=> callback, but I think that would just complicate the code. You'd have to specify what values to split, because you'd definitely not want to split everything that contains the delimiter. So I think it's better to split after everything is read.@files = split /\s*,\s*/, $config->{path}{files}; # the \s* removes the optional whitespace around delimiters
If you did want to modify the $config structure to contain certain values as arrays you might do something like this:
After this the $config->{anySection}{files} is no longer a string but a reference to an anonymous array containing the individual items.foreach my $Section (values %$config) { # $Section is a hash ref containing the values of the section, not th +e section name! foreach my $value (qw(files colors and other options that should be +arrays)) { $Section->{$value} = [split /\s*,\s*/, $Section->{$value}]; } }
Jenda
|
We'd like to help you learn to help yourself Look around you, all you see are sympathetic eyes Stroll around the grounds until you feel at home -- P. Simon in Mrs. Robinson |
In reply to Re^5: Config files
by Jenda
in thread Config files
by sparkel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |