Reading a dot symbol (.) in perl

2019-06-14 19:45发布

问题:

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?

回答1:

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.



回答2:

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


标签: perl cgi symbols