tags:

views:

60

answers:

2

I need change a value in a ini file like this val2 is the one being changed

Before

[section1]

var1=val1

var2=val2

var3=va3

After:

[section1]

var1=val1

var2=value

var3=va3
+5  A: 

If you want to do it the best way use the appropriate distro for rewriting the .ini file. Here is an overview of the API.

use strict;
use warnings;
use Config::INI::Reader;
use Config::INI::Writer;

my $ini = Config::INI::Reader->read_handle( *DATA );
$ini->{section1}{var2} = 'value';

print Config::INI::Writer->write_string( $ini );


__DATA__

[section1]

var1=val1

var2=val2

var3=va3
Evan Carroll
A: 

Find Config::Std on CPAN.

xcramps