G'day perlPsycho,

I'm not sure why you're creating both a Config::IniFiles object and a tied hash. I was able to get the output you wanted with each one, independent of the other.

In pm_1164267_config_inifiles.pl:

Source of pm_1164267_config_inifiles.pl:

#!/usr/bin/env perl -l use strict; use warnings; use constant { IN_SEP => ( defined $ARGV[0] ? $ARGV[0] : ' ' ), OUT_SEP => ( defined $ARGV[1] ? $ARGV[1] : ' ' ), SECTION => ( length $ARGV[2] ? $ARGV[2] : 'hello'), PARM => ( length $ARGV[3] ? $ARGV[3] : 'j'), INI => ( length $ARGV[4] ? $ARGV[4] : 'pm_1164267_config_inifiles. +ini' ), }; use Config::IniFiles; { my $cfg = Config::IniFiles::->new( -file => INI ); my $j_str = $cfg->val( SECTION, PARM ); process_j_str($j_str); } { tie my %ini, 'Config::IniFiles', ( -file => INI ); my $j_str = $ini{+SECTION}{+PARM}; untie %ini; process_j_str($j_str); } sub process_j_str { my ($j_str) = @_; my @j_vals; _populate_j_vals_array($j_str, \@j_vals); _print_with_seps(\@j_vals); } sub _populate_j_vals_array { my ($j_str, $j_vals) = @_; my $i = 0; for (0 .. length($j_str) - 1) { my $char = substr $j_str, $_, 1; if ($char eq IN_SEP) { ++$i if length $j_vals->[$i]; } else { $j_vals->[$i] .= $char; } } } sub _print_with_seps { my ($j_vals) = @_; { local $" = OUT_SEP; print "j=@$j_vals"; } }

pm_1164267_config_inifiles.ini starts with the same data you provided. I've added half a dozen lines to test what you described in "Re^2: Using Config::IniFiles Module Obtain Comma Separated Values into An Array".

$ cat pm_1164267_config_inifiles.ini # # # # # # [hello] # # # # i=abc i=def i=ghi i=jkl i=mno j=abc def ghi jkl mno pqrs tuv wxyz [spaces] j=abc def ghi jkl mno pqrs tuv wxyz [commas] j=abc,def,ghi,jkl,mno,pqrs,tuv,wxyz [dots] j=abc.def.ghi.jkl.mno.pqrs.tuv.wxyz

Here's some sample runs:

$ pm_1164267_config_inifiles.pl j=abc def ghi jkl mno pqrs tuv wxyz j=abc def ghi jkl mno pqrs tuv wxyz
$ pm_1164267_config_inifiles.pl ' ' j=abc def ghi jkl mno pqrs tuv wxyz j=abc def ghi jkl mno pqrs tuv wxyz
$ pm_1164267_config_inifiles.pl ' ' , j=abc,def,ghi,jkl,mno,pqrs,tuv,wxyz j=abc,def,ghi,jkl,mno,pqrs,tuv,wxyz

Testing the additional INI lines:

$ pm_1164267_config_inifiles.pl ' ' : spaces j=abc:def:ghi:jkl:mno:pqrs:tuv:wxyz j=abc:def:ghi:jkl:mno:pqrs:tuv:wxyz
$ pm_1164267_config_inifiles.pl , % commas j=abc%def%ghi%jkl%mno%pqrs%tuv%wxyz j=abc%def%ghi%jkl%mno%pqrs%tuv%wxyz
$ pm_1164267_config_inifiles.pl . , dots j=abc,def,ghi,jkl,mno,pqrs,tuv,wxyz j=abc,def,ghi,jkl,mno,pqrs,tuv,wxyz

— Ken


In reply to Re: Using Config::IniFiles Module Obtain Comma Separated Values into An Array by kcott
in thread Using Config::IniFiles Module Obtain Comma Separated Values into An Array by perlPsycho

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.