Delta
Delta

Reputation: 2022

How do I perform a simple modification of an .ini file in perl?

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

Upvotes: 0

Views: 170

Answers (2)

xcramps
xcramps

Reputation: 1213

Find Config::Std on CPAN.

Upvotes: 0

Evan Carroll
Evan Carroll

Reputation: 1

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

Upvotes: 6

Related Questions