我有一個文件類似以下內容找到特定的標記,並取代所有領域下它在Perl
[amrit]
type=friend
host=111.118.253.145
port=2776
username=amrit
secret=password
disallow=all
allow=gsm
context=sip-calling
qualify=yes
call-limit=22
[windwos]
type=friend
host=111.118.253.145
port=2775
username=amrit
secret=password
disallow=all
allow=gsm
context=sip-calling
qualify=yes
call-limit=50
[windwos121254]
type=friend
host=111.118.253.145
port=2776
username=amrit
secret=password
disallow=all
allow=ulaw
allow=alaw
context=sip-calling
qualify=yes
call-limit=99
現在我想建立在Perl腳本。這會發現所有這個標籤下的[阿姆裏特]
type=friend
host=111.118.253.145
port=2776
username=amrit
secret=password
disallow=all
allow=gsm
context=sip-calling
qualify=yes
call-limit=22
現在我想更新的每個字段的值都行,但值應該是這個標籤的變化只是我一直在使用Perl腳本找到這些線,但我我無法改變這些檔案的價值。腳本如下
#!/usr/bin/perl
$count = 0;
open (IN, "file.txt");
while (<IN>) {
if (/\[amrit\]/) {
$count = 1;
}
elsif (/\[*\]/) {
$count = 0;
}
elsif ($count) {
print;
}
}
close IN;
現在我想要更新[amrit]標記中每行的值。我是perl的初學者,請在這裏幫助我。
設定值如果是一個INI文件,你可以使用['配置:: INI'(HTTP: //search.cpan.org/perldoc?Config%3A%3AINI)。 – TLP
好吧,你所有的價值都要改變或者一些特殊的標籤? – JackXu
@TLP它是一個conf文件 – user2916639