Reading a dot symbol (.) in perl

2019-06-14 19:36发布

I have a .conf file which looks like this:

[offline_online_status]
offline_online_status.offline_online_state=ONLINE

How can perl read the dot symbol (.) in the value above? Can anybody teach me?

标签: perl cgi symbols
2条回答
Rolldiameter
2楼-- · 2019-06-14 20:11

maybe you can adapt this to what you need to do:

$ 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
查看更多
祖国的老花朵
3楼-- · 2019-06-14 20:12

Try to use this, make your own modification:

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"};

And after that just print the $status_in_file. This code will read the entire key and value in your configuration file.

查看更多
登录 后发表回答