我有一个.conf文件,如下所示:
[offline_online_status]
offline_online_status.offline_online_state=ONLINE
perl如何读取上面值中的点符号(。)?任何人都可以教我吗?
答案 0 :(得分:0)
也许你可以根据自己的需要进行调整:
$ cat ./test.pl
#!/usr/bin/perl
while(<DATA>) {
next if /\[online_offline_status]/;
my @arr = split /\./;
print "." . $arr[1];
}
__DATA__
[online_offline_status]
online_offline_status.online_offline_state = ONLINE
$ ./test.pl
.online_offline_state = ONLINE
答案 1 :(得分:0)
尝试使用此功能,进行自己的修改:
use CGI;
use Config::Tiny;
use Data::Dumper;
use CGI::Carp qw(fatalsToBrowser);
#location/directory of configuration file
my $file = "your configuration file path";
my $Config = Config::Tiny->read($file);
#reads the section, key and the value of the configuration file.
my $status_in_file = $Config->{"offline_online_status"}->{"offline_online_status.offline_online_state"};
之后只需打印$ status_in_file。此代码将读取配置文件中的整个键和值。