perl config parser


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl config parser
# 1  
Old 03-30-2009
perl config parser

Hello.
Can anybody help me with some sub on perl that can parse config like this:
Code:
%CFG (
   'databases' => {
      'db1' => 'db_11', 'db_12', 'db_13',
      'db2' => 'db_21', 'db_22', 'db_23'
   }
   'datafiles' => {
      'datadir1' => 'datadir_11', 'datadir_12',
      'datadir2' => 'datadir_21', 'datadir_22'
   }
   log => {
      'logfile' => '/var/log/logfile'
      'loglevel' => 'warn'
   }
)




It should something like hash of hashes, but the following code but I don't know how to parse multiple values of db1...
Does anybody know how to change it to be accessed like
$CFG::CFG{'databases'}{'db1'}

Last edited by Yogesh Sawant; 03-30-2009 at 11:37 AM.. Reason: added code tags
# 2  
Old 03-31-2009
not quiet sure about your concern, but below should work

Code:
$CFG->{databases}->{db1}

# 3  
Old 03-31-2009
If you want a simple way to read a file to such a structure, use YAML, eg via Config::YAML. If it's something else you want, please be more clear and complete on your explanation.
# 4  
Old 03-31-2009
Quote:
Originally Posted by drack
Hello.
Can anybody help me with some sub on perl that can parse config like this:
Code:
%CFG (
   'databases' => {
      'db1' => 'db_11', 'db_12', 'db_13',
      'db2' => 'db_21', 'db_22', 'db_23'
   }
   'datafiles' => {
      'datadir1' => 'datadir_11', 'datadir_12',
      'datadir2' => 'datadir_21', 'datadir_22'
   }
   log => {
      'logfile' => '/var/log/logfile'
      'loglevel' => 'warn'
   }
)




It should something like hash of hashes, but the following code but I don't know how to parse multiple values of db1...
Does anybody know how to change it to be accessed like
$CFG::CFG{'databases'}{'db1'}

The code you posted is not valid perl code. Do you need to know how to write the code to make a hash of hashes or hash of arrays or what?
# 5  
Old 03-31-2009
Quote:
Originally Posted by KevinADC
The code you posted is not valid perl code. Do you need to know how to write the code to make a hash of hashes or hash of arrays or what?
Seems I was not clear in my question. I just need some structured config with multiply values for key. (You see in config 'db2' => 'db_11', 'db_12', that is not valid. Valid only 'db2' => 'db_11'). seems YAML is way I should going through.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to run different parser based on digit

The perl parser below works as expected assuming the last digit in the NC_ before the . is a single digit. perl -ne 'next if $. == 1; if(/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+)/) # indel { print join("\t", $3, $4, $5, $1, $2), "\n"; } ' out_position.txt > out1.txt ... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

Update perl code with parser

The below perl code imports the data in the attached document. However, I can not seem to update the perl code to include a parser like in the desired tab of that document. Thank you :). Most of the data for the parse is included in the document except for the gene and RNA which can is... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Help required in Building an XML using SAX Parser in perl

I want to use sax parser for my application as i have 5 Lakhs of data. I have the xml file like this <Nodes> <Node> <NodeName>Company</NodeName> <File>employee_details.csv</File> <data>employee_data.txt</data> <Node> <NodeName>dummy</NodeName> ... (8 Replies)
Discussion started by: vanitham
8 Replies

4. Programming

Parser - multiple in Perl

Dear Perl Experts, Could some body help me to find the solution for my problem below: Input file: ----------- THE-0 tsjp THE-32 tsjp THE-64 tsjp Output desired: --------------- THE-0&&-31 tsjp THE-32&&-63 tsjp THE-64&&-95 tsjp Note: 31 = 0+31, (2 Replies)
Discussion started by: askari
2 Replies

5. Shell Programming and Scripting

Facing problem in XML::parser module in PERL

HI, I have XML file which is having values as Spanish character (UTF-8 encoding). I am using XML::parser module but my code is not able to read those characters. I did goggling but not able to find suitable solution. Anybody please help me out. XML file having characters like: ñ I am... (1 Reply)
Discussion started by: jatanig
1 Replies

6. Shell Programming and Scripting

xml-parser with perl

Hello I want to write an xml- parser with perl an i use the libary XML::LibXML. I have a problem with the command getElementsByTagName. If there is an empty tag, the getElementsByTagName method returns a NodeList of length zero. how can i check if this is a nodelist of lenght zero?? i... (1 Reply)
Discussion started by: trek
1 Replies

7. Shell Programming and Scripting

Perl XML:Parser help

I am very new to XML. Really I have an excel file that I am trying to read w/ Perl on a Linux machine. I don't have a mod for reading excel files so I have to convert the excel file to xml to be able to read it. I can read the file and everything is ok except...the Number style is being dropped... (0 Replies)
Discussion started by: vincaStar
0 Replies

8. Shell Programming and Scripting

xml parser in perl

hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file removing xml file due to some reason (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question