Parsing config-file (perl)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing config-file (perl)
# 1  
Old 09-18-2010
Parsing config-file (perl)

Hi,

i'm trying to parse a config file that have alot of rows similar to this one:

Example value value value

What i want to do is to split and save the row above in a hash, like this:

Example = value value value

Basically i want to split on the first whitespace after the first word/directive.

Thanks!
# 2  
Old 09-18-2010
You can use split to split the lines into lists, see "perldoc -f split". Once you have the list, you can pull the first value off the list with shift, see "perldoc -f shift".
# 3  
Old 09-18-2010
Thanks!
# 4  
Old 09-18-2010
Quote:
Originally Posted by Corona688
You can use split to split the lines into lists, see "perldoc -f split". Once you have the list, you can pull the first value off the list with shift, see "perldoc -f shift".
Or use my favourite hammer, regex. Assuming $_ is defined:

Code:
/([^ ]*) (.*)/ and $hash{$1} = $2;

man perlre
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

.Config file in perl

Hi can anybody help me in how to read .config file in Perl, which module is used, and some help in coding. (10 Replies)
Discussion started by: parthmittal2007
10 Replies

2. 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

3. Shell Programming and Scripting

parsing a config file using bash

Hi , I have a config _file that has 3 columns (Id Name Value ) with many rows . In my bash script i want to be able to parse the file and do a mapping of any Id value so if i have Id of say brand1 then i can use the name (server5X) and Value (CCCC) and so on ... Id Name ... (2 Replies)
Discussion started by: nano2
2 Replies

4. Shell Programming and Scripting

Read from config file and use it in perl program

Hi, I want to configure some values in config file like below 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) ? ... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

5. Shell Programming and Scripting

Need help parsing config file in ksh

Hi all, I've done some searching here but haven't found exactly what I'm looking for so I thought I'd post up and see if someone can help out. I'm working on a shell script that I would like to store environment variables in an external file. I'm familiar with sourcing a file with variables in... (1 Reply)
Discussion started by: kungfusnwbrdr
1 Replies

6. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

7. Shell Programming and Scripting

Parsing config file

Hi All, I have a requirement to parse a file. Let me clear you all on the req. I have a job which contains multiple tasks and each task will have multiple attributes that will be in the below format. Each task will have some sequence number according to that sequence number tasks shld... (0 Replies)
Discussion started by: rajeshorpu
0 Replies

8. Shell Programming and Scripting

Perl config file Help

Hi In My config file i have 12.122.12.111:2000 A host and a port number. To read the config file i have written in a perl script like this my %config; open my $config, '<','config' or die "Failed to read file :$!"; Its running fine in HP-UX but showing error in solaris... (2 Replies)
Discussion started by: Harikrishna
2 Replies

9. 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

10. Shell Programming and Scripting

Perl config file Help

Hi can anyone help me understanding the following code my %config; open my $config, '<', 'config.txt' or die $!; while(<$config>) { chomp; (my $key, my @value) = split /=/, $_; $config{$key} = join '=', @value; } (5 Replies)
Discussion started by: Harikrishna
5 Replies
Login or Register to Ask a Question