in reply to Using Config::IniFiles Module Obtain Comma Separated Values into An Array

Hello,

it seems i cannot install Config::IniFiles on my Strawberry Perl, but reading the docs

# If you want a multi-line/value field returned as an array, just sp +ecify an array as the receiver: @values = $cfg->val('Section', 'Parameter');

it seems to me you are doing correctly: it is not your @arr array populated? I'm missing your question?

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Using Config::IniFiles Module Obtain Comma Separated Values into An Array
by perlPsycho (Initiate) on May 27, 2016 at 07:23 UTC
    Hello Discipulus,

    Thank you for taking the time to Notice and Reply :) :).

    The Previous set of population was by using
    i=abc i=def .... i=wxyz.
    This works perfectly fine.

    But there is some other Way to populate an array by using space,comma(s),dot(s) by default.

    like ...
    j=abc def ghi jkl mno pqrs tuv wxyz<br> j=abc,def,ghi,jkl,mno,pqrs,tuv,wxyz<br> j=abc.def.ghi.jkl.mno.pqrs.tuv.wxyz<br>
    I need this way of Obtaining he values in an array.

      Config::IniFiles, as many other modules, is meant as a versatile instrument and therefore allows spaces, commas, etc. as part of the configuration values. So you seem to be out of luck.

      Discipulus' hint is the best you can get, except he didn't quote the last sentence of that section:
      A multi-line/value field that is returned in a scalar context will be joined using $/ (input record separator, default is \n) if defined, otherwise the values will be joined using \n.
      So you'd have to decide beforehand which separator to use - EITHER space OR comma OR dot (OR whatever) - and go for something like
      my @arr; { local $/ = ' '; @arr=$cfg->val('hello','j'); }
      $/ is a Perl builtin, see perlvar (search for $RS), so it's not a "third party method".

      Sorry, that was wrong, describing the module's behaviour for returning a multivalue as a scalar. But what's wrong with Corion's suggestion? split is also a Perl builtin, not "third party".

      OR make the multiline field in the ini file conform to the format specified in the "FILE FORMAT" section of the module's documentation…

      Have you considered using split to split up the values?

        Hello Corion,

        Thanks for the reply :D .

        No I cant,I cannot do that.
        Splitting it by values would get me the result.
        But that's the constraint,
        I cant use Split by values or Regex or Any third Party Methods other than Config::IniFiles.

        This is where it gets Complicated. D: D: D:

          A reply falls below the community's threshold of quality. You may see it by logging in.