Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Problem with Config::IniFiles multi-valued parameters and WriteConfig

by Anonymous Monk
on Jul 13, 2009 at 09:48 UTC ( #779511=note: print w/replies, xml ) Need Help??


in reply to Problem with Config::IniFiles multi-valued parameters and WriteConfig

I don't think it is supported.
None of these modules fully support it.
#!/usr/bin/perl -- # Save as test.pl with test.pl.ini use strict; use warnings; use Data::Dumper; { # no way to override EOT heredoc multi use Config::IniFiles; my $cfg = Config::IniFiles->new( -file => __FILE__.'.ini' ) or die "error: IniFiles->new: @Config::IniFiles::errors"; my @values = $cfg->val( 'Trace', 'TRACE_MODULE' ); warn Dumper( \@values ),"\n . "; $cfg->WriteConfig( __FILE__.'.2.ini') or die "error: WriteConfig: +$!\n . "; use Shell::Command qw[ cat ]; cat __FILE__.'.ini'; cat __FILE__.'.2.ini'; } { # no multi support use Config::Tiny; my $Config = Config::Tiny->read( __FILE__ . '.ini' ); warn Dumper($Config),"\n . "; $Config->{Trace}{TRACE_MODULE} = [ qw[ mod1 mod2 ] ]; warn $Config->write_string,"\n . "; } { # multi via CSV ie TRACE_MODULE=mod1,mod2 use Config::Simple; my $cfg = Config::Simple->new( __FILE__.'.ini'); warn Dumper($cfg),"\n . "; } { # output is buggy (reversed... use Config::General; my $conf = new Config::General( -SplitPolicy => 'equalsign', -AllowMultiOptions => 'yes', # this is default -ConfigFile => __FILE__.'.ini', ); my %config = $conf->getall; warn Dumper( \%config ),"\n . "; warn $conf->save_string( \%config ),"\n . "; $conf->save_file( __FILE__.'.2.ini', \%config); use Shell::Command qw[ cat ]; cat __FILE__.'.2.ini'; } { # not for writing ini files, but for reading/validating use AppConfig; my $config = AppConfig->new({ PEDANTIC => 1, CASE => 1, }); $config->define( 'Trace_TRACE_MODULE=s@', ); $config->file( __FILE__.'.ini'); warn Dumper($config),"\n . "; warn $config->_dump,"\n . "; } { # no multi use Config::INI; # should do more than just declare package/pod use Config::INI::Reader; my $hash = Config::INI::Reader->read_file( __FILE__.'.ini'); warn Dumper($hash),"\n . "; } { # NOT allowmultiple for WriteINI use Config::IniHash; my $Config = ReadINI __FILE__.'.ini', allowmultiple => 1, ; warn Dumper( $Config ) ,"\n . "; WriteINI( __FILE__.'.2.ini', $Config ); use Shell::Command qw[ cat ]; cat __FILE__.'.ini'; cat __FILE__.'.2.ini'; } { # promising, but write_file is undocumented use Config::Mini; # write_file isn't a method either #~ my $config = Config::Mini->new ( __FILE__.'.ini', ); #~ warn Dumper( $config ) ,"\n . "; Config::Mini::parse_file ( __FILE__.'.ini', ); warn Dumper( \%Config::Mini::CONF ) ,"\n . "; Config::Mini::write_file ( __FILE__.'.2.ini', ); close Config::Mini::FP; # bug in Config::Mini 0.04 use Shell::Command qw(cat); cat( __FILE__.'.ini' ); cat( __FILE__.'.2.ini' ); }
I would submit a patch for Config::IniFiles, and subclass Config::IniFiles for personal use.
  • Comment on Re: Problem with Config::IniFiles multi-valued parameters and WriteConfig
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://779511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-05-15 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?