I searched the module for reading Example Config File: Coding: Here is an easy way to use Output: which must be given for more information. It becomes simpler with give Therefore the share of You can learn more in Config ,
Config :: config files Small is ,
config: simple . I am not very obscure about the use of those people, are there any modules for reading / reading DBI config and username / password? I have tried to do this myself, I want a config file in a hash data structure to import easy in my module. Is it an easy way to try that which I am trying / or a favorite module which can be suggested?
[database] db = newsdb host = example .com user = test pass = test [login] user = john pass = doe
Use strict; Use warnings; Use the file: Slurp; Use data: Dumper; # Get the database information from my% conf = map {/ ^ \ [database /? (): $ _} Grep {/^\w+.*$/} Map {/? S? \ N? \ R? // g; (Partition / = /) [0,1]} read_file ('database.conf'); Print dumper \% Conf; $ VAR1 = {'pass' = & gt; 'Test', 'db' = & gt; 'Newsby', 'User' = & gt; 'Test', 'host' = & gt; 'Example.com'};
Use the config module to not read configuration files Instead it gives detailed information on the configuration of your
perl .
config :: simple , and then
config: simple-> import_from ("database. Conf "= & gt; \ my% config); Print dumper% config;
$ VAR1 = {'database.host' = & gt; 'Example.com', 'login.pass' = & gt; 'DO', 'Login. User '= & gt; 'John', 'Database.User ='> 'Test', 'database.db' = & gt; 'News', 'database.pass' = & gt; 'testing' }; Alternatively, to use only one block, we can do
my $ config = Config :: Simple-> New ("database.conf"). ) - & gt; Get_block ("database"); Print dumper $ config;
$ VAR1 = {'pass' = & gt; 'Test', 'db' = & gt; 'Newsby', 'User' = & gt; 'Test', 'host' = & gt; 'Example.com'}; As output, read
Config :: Tiny :
my $ config = Configure Tiny- & Gt; Read ("database.conf"); Print dumper $ config;
$ VAR1 = blessing ({'database' => {'pass' => 'test', 'db' = & Gt; 'newdib', 'user' => gtc: test = 'host' = & gt; example.com '},' login '=> {' pass '= & gt;' dow ',' Users' = & gt; 'John'}}, 'Config :: Tiny');
database
print dumpor $ config- & gt; Can be selected with {database} which will output
$ VAR1 = {'pass' => 'Test', 'db' = & gt; 'Newsby', 'User' = & gt; 'Test', 'host' = & gt; 'Example.com'};
No comments:
Post a Comment