开发者

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=va开发者_如何转开发l1

var2=value

var3=va3


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


Find Config::Std on CPAN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜