我有sample.ini文件
Sample.ini
[Section1]
workers=3
port=8500
;
[Section2]
student=7
port=7688
;
如何从Section1读取worker值并更新到workers = 8
预期结果
[SECTION1] 工人= 8 ...
先谢谢。
答案 0 :(得分:2)
试试这个模块。我认为这正是你想要的:Config::IniFiles
use Config::IniFiles;
$cfg = Config::IniFiles->new( -file => "Sample.ini" );
$value = $cfg->val( 'Section1', 'workers' );
$value = $value + 5;
$cfg->setval( "agent", "numworkers", $value );
$cfg->WriteConfig( 'agent.ini', -delta => 1 );