The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl config file Help Harikrishna Shell Programming and Scripting 2 05-21-2008 09:07 PM
Perl config file Help Harikrishna Shell Programming and Scripting 5 05-19-2008 01:40 AM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-09-2007 11:25 PM
using config file mape Shell Programming and Scripting 1 09-06-2006 10:37 PM
Perl CGI to access / edit "root" owned config files WIntellect Shell Programming and Scripting 1 04-23-2003 12:48 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-16-2008
Registered User
 

Join Date: Feb 2008
Posts: 38
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 function ...Please Help
Reply With Quote
Forum Sponsor
  #2  
Old 05-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
my ($host, $port) = split /:/;
If the input line still has a trailing newline at this point, you want to chomp it first.
Reply With Quote
  #3  
Old 05-16-2008
Registered User
 

Join Date: Feb 2008
Posts: 38
Quote:
Originally Posted by era View Post
Code:
my ($host, $port) = split /:/;
If the input line still has a trailing newline at this point, you want to chomp it first.
I am newbee in perl i want to open this configfile in a perl script. so how to read this config file from a perl script and get the host and port number..
plz help
Reply With Quote
  #4  
Old 05-17-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 791
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);
Reply With Quote
  #5  
Old 05-18-2008
Registered User
 

Join Date: Feb 2008
Posts: 38
Quote:
Originally Posted by Yogesh Sawant View Post
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);


HI Yogesh

my $filename = shift;
my %host_info = ();

These two syntax giving error..
How i could give my $filename = shift;????
Reply With Quote
  #6  
Old 05-19-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 791
what error do you see?
Reply With Quote
  #7  
Old 05-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 38
Quote:
Originally Posted by Yogesh Sawant View Post
what error do you see?
Hi Yogesh it worked.. Thanks a lot....
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
perl script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0