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

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