私はConfig::IniFiles Perlモジュールを使用したいと思います。 Ubuntuはapt-get ...
を使用するために
$ sudo yum install perl-Config-IniFiles
:あなたがRedHatのかCentOSにシステム上で実行している場合は、これを試してみてください。
ここでコンフィグからサンプルスクリプトの修正版::をIniFileの概要です:
$ cat syn.pl
#!/bin/perl -w
use strict;
use Config::IniFiles;
my $cfg = Config::IniFiles->new(-file => "./inifile.ini");
print "The value is " . $cfg->val('Block2', 'here') . ".\n"
if $cfg->val('Block2', 'here');
は、ここで実行する例を示しますBlock2
でhere
を変更
$ cat inifile.ini
[Block1]
this=that
here=there
why=why_not
[Block2]
this=those
here=there
why=because
$ ./syn.pl
The value is there.
は簡単です:
$ cat rewrite.pl
#!/bin/perl -w
use strict;
use Config::IniFiles;
my $cfg = Config::IniFiles->new(-file => "./inifile.ini");
print "The value is " . $cfg->val('Block2', 'here') . ".\n"
if $cfg->val('Block2', 'here');
$cfg->setval('Block2', 'here', 'anywhere');
$cfg->RewriteConfig();
$ cat inifile.ini
[Block1]
this=that
here=there
why=why_not
[Block2]
this=those
here=there
why=because
$ ./rewrite.pl
The value is there.
$ cat inifile.ini
[Block1]
this=that
here=there
why=why_not
[Block2]
this=those
here=anywhere
why=because
ブロックを後で再結合するのはどうですか?ブロックの順序は重要ですか? –
このユースケースではありません。 – Chip