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:

[path] files=foo.txt,bar.txt,baz.csv
you'd just need to do something like:
@files = split /\s*,\s*/, $config->{path}{files}; # the \s* removes the optional whitespace around delimiters
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.

If you did want to modify the $config structure to contain certain values as arrays you might do something like this:

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}]; } }
After this the $config->{anySection}{files} is no longer a string but a reference to an anonymous array containing the individual items.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.