当前位置: 动力学知识库 > 问答 > 编程问答 >

perl - How to use Config::IniFiles module to read files

问题描述:

I have been using multiple files for reading different types of configurations but I understand that I might be able to use Config::IniFiles modules and use a single file. My files structure is something like below, can someone help me in understanding how to achieve this. I have been using normal open command for different files, so another question is whether that will be directly replaced by this. Please note that I have to loop through each section

NOTE: earlier I had each [DomainCredentials] And [ProviderCredentials] in different files

[DomainCredentials]

DomainName=SERVER

CustomerCOde=CUSTOMER1

[ProviderCredentials]

Class=A

Routine=B

网友答案:

I'm not sure exactly what you are asking for, but:

use strict;
use warnings;
use Config::Tiny;

my $config = Config::Tiny->new()->read("config.txt");

print $config->{'DomainCredentials'}{'DomainName'}, "\n";

yields:

SERVER
分享给朋友:
您可能感兴趣的文章:
随机阅读: