Sponsored Content
Full Discussion: Perl config file Help
Top Forums Shell Programming and Scripting Perl config file Help Post 302196194 by Yogesh Sawant on Saturday 17th of May 2008 05:05:57 AM
Old 05-17-2008
here you go:
Code:
#!/usr/bin/perl
# read_config.pl
my $filename = shift;
my %host_info = ();
open (CONF_FILE, '<', $filename)  or  die "Failed to read file $filename : $!";
while (<CONF_FILE>) {
    chomp;
    next  if (m/^$/);        # Skip empty lines
    next  if (m/^\s*#/);    # Skip comments
    if (m/^(.*?):(\d+)/) {
        $host_info{$1} = $2;
    }
}
close (CONF_FILE);

 

10 More Discussions You Might Find Interesting

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

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

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

4. Shell Programming and Scripting

SOLVED: reading config file in a perl script

Hi! I have a need to do this in Perl. script.pl -config file The script would be doing a wget/LWP on a URL which is defined in the config file. So when I run the script it should return either one of these conditions - 1) OK with exit status 0. Should also print "wget URL" 2)... (6 Replies)
Discussion started by: jacki
6 Replies

5. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: mikemikemike
3 Replies

6. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

7. Shell Programming and Scripting

PERL on windows accessing variables from a config file

Folks, I'm a perl moron, so please speak very slowly. : ) I'm modifying a build script that starts up an apache server. Now there is a .config file that hardcodes an old webserver path like this c:\oldWebserver. Now I don't want that hardcoded value, rather wish to use an... (3 Replies)
Discussion started by: MarkoRocko
3 Replies

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

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

10. 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
Config::MVP::Reader(3pm)				User Contributed Perl Documentation				  Config::MVP::Reader(3pm)

NAME
Config::MVP::Reader - object to read config from storage into an assembler VERSION
version 2.200002 SYNOPSIS
use Config::MVP::Reader::YAML; # this doesn't really exist my $reader = Config::MVP::Reader::YAML->new; my $sequence = $reader->read_config('/etc/foobar.yml'); DESCRIPTION
A Config::MVP::Reader exists to read configuration data from storage (like a file) and convert that data into instructions to a Config::MVP::Assembler, which will in turn convert them into a Config::MVP::Sequence, the final product. METHODS
read_config my $sequence = $reader->read_config($location, \%arg); This method is passed a location, which has no set meaning, but should be the mechanism by which the Reader is told how to locate configuration. It might be a file name, a hashref of parameters, a DBH, or anything else, depending on the needs of the specific Reader subclass. It is also passed a hashref of arguments, of which there is only one valid argument: assembler - the Assembler object into which to read the config If no assembler argument is passed, one will be constructed by calling the Reader's "build_assembler" method. Subclasses should generally not override "read_config", but should instead implement a "read_into_assembler" method, described below. read_into_assembler This method should not be called directly. It is called by "read_config" with the following parameters: my $sequence = $reader->read_into_assembler( $location, $assembler ); The method should read the configuration found at $location and use it to instruct the $assembler (a Config::MVP::Assembler) what configuration to perform. The default implementation of this method will throw an exception complaining that it should have been implemented by a subclass. build_assembler If no Assembler is provided to "read_config"'s "assembler" parameter, this method will be called on the Reader to construct one. It must return a Config::MVP::Assembler object, and by default will return an entirely generic one. AUTHOR
Ricardo Signes <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-03-16 Config::MVP::Reader(3pm)
All times are GMT -4. The time now is 04:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy