Read from config file and use it in perl program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read from config file and use it in perl program
# 1  
Old 06-07-2011
Read from config file and use it in perl program

Hi,

I want to configure some values in config file like below

HTML Code:
work_dir /home/work 
csv_dir /home/csv 
sql_dir /home/sqls 
reportfirst yes

and i want to store each value in variable to use it further in my my perl program ??


any thought on this(i am new to perl) ?

Thanks,
Raghavendra
# 2  
Old 06-07-2011
This is what I am already using in my programs

config file:

Code:
# comments are allowed 
work_dir = /home/work
csv_dir = /home/csv 
sql_dir = /home/sqls 
reportfirst = yes


In script:

Code:
my %configParamHash = ();
open ( _FH, $configFileName ) or die "Unable to open config file: $!";
 
while ( <_FH> ) {
    chomp;
    s/#.*//;                # ignore comments
    s/^\s+//;               # trim leading spaces if any
    s/\s+$//;               # trim leading spaces if any
    next unless length;
    my ($_configParam, $_paramValue) = split(/\s*=\s*/, $_, 2);
    $configParamHash{$_configParam} = $_paramValue;
}
close _FH;


Now%configParamHash will contain the key-value pair of the config values.

e.g.

Code:
my $_csvDir = $configParamHash{csv_dir};

# 3  
Old 06-07-2011
Have a look at Config::IniFiles as well.

Config::IniFiles - search.cpan.org
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read Data from Config file using Perl

Hi All, Can anyone please explain me how to read data from config file in Perl. Suppose i have a config file named cfile. The data in config file is name=parth lname=mittal user=2007 hostname=fluoride username=parthmittal password=XXXXXX account=unix url=www.unix.com ... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

2. Shell Programming and Scripting

how to read the variable indivdually from config file

how to read the variable indivdually ( line by line ) in shell script eg : i have the config file where contain cat /home/user01/ilap/conf/input.conf node.txt node2.txt node3.txt i need to run script like /home/user01/ilap/exe/run.sh /home/user01/ilap/conf/input.conf ... (1 Reply)
Discussion started by: mail2sant
1 Replies

3. Programming

Read arguments from a config file in C

Hello everybody, I'm coding a program in C and i'm getting troubles with this. I need to read a config file and store the arguments into individual variables, let's say the config file looks like the following: #This is the configuration file... 192.168.0.1 A1:B1:C1:D1:E1:F1 192.168.0.2... (2 Replies)
Discussion started by: semash!
2 Replies

4. Solaris

Autosys Config file update on a read-only filer

Hi To All Genius out there, We are running autosys application on solaris 10. In autosys we have a configuration file that contains an Autosys instance configuration data and is located on a NFS filer on which we have a read-only access. Our Autosys environment is on a dual server mode(Active... (0 Replies)
Discussion started by: whn_chips_r_dwn
0 Replies

5. UNIX and Linux Applications

Autosys Config file update on a read-only filer

Hi To All Genius out there, We are running autosys application on solaris 10. In autosys we have a configuration file that contains an Autosys instance configuration data and is located on a NFS filer on which we have a read-only access. Our Autosys environment is on a dual server... (0 Replies)
Discussion started by: whn_chips_r_dwn
0 Replies

6. Shell Programming and Scripting

Read from a config file.

Hello All, I have a config file which has the following data : export DBCHECKSUM001="/home/srvcdesk/DBCheckSum/DBCheckSum001.cfg" export DBCHECKSUM002="/home/srvcdesk/DBCheckSum/DBCheckSum002.cfg" export DBCHECKSUM003="/home/srvcdesk/DBCheckSum/DBCheckSum003.cfg" export... (1 Reply)
Discussion started by: Veenak15
1 Replies

7. Shell Programming and Scripting

how to read the variable from config file

how to read the variable from config file eg: a.cfg below config file config file which contain a=`hostname` b=250 a.sh is shell script echo "$a and $b" if i run "a.sh 1.cfg" it works but when i declare N number of variable it wont works.. can u please suggest for that ? (1 Reply)
Discussion started by: mail2sant
1 Replies

8. Shell Programming and Scripting

Perl config file Help

HI I have a config file (ip.config)that has the following fields with colon as delimeter. yahoo.com:1919 ( host and port number) rediffmail.com:2020 gmail.com:2121 How to read it in a perl script. I need to parse the host and port number in the perl script using split... (6 Replies)
Discussion started by: Harikrishna
6 Replies

9. UNIX for Dummies Questions & Answers

How to Read a config file and Assign to Variable

I have removeConfig file, it contains the dir paths for removing. I need to read line by line and assign to variable. any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies

10. Shell Programming and Scripting

Perl program to read from multiple files

Hi, I need to generate a test data file by reading inputs from multiple files. A sample pseudo code for this program to read from three files and write to a output file would be like: open(OUTPUTFILE, "data"); open(INFILE1, "data1"); open(INFILE2, "data2"); open(INFILE3, "data3"); ... (1 Reply)
Discussion started by: jyotipg
1 Replies
Login or Register to Ask a Question