CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Read from a header file like C

 



gvenkat
Novice

Aug 4, 2016, 7:05 AM

Post #1 of 9 (2756 views)
Read from a header file like C Can't Post

I have a few programs in my environment that has the following values hard coded.

Port Number - 1000
host name - abc01.xyz.com
username - gvenkat
password - ganesh99

This is the format that has been hard coded.

//Existing Format

my $port = 1000;
if ( ! $opt_p ){
$port = 1000;
} else {
$port = $opt_p;
}

$dbh = DBI->connect("DBI:mysql:database=$dbnam;host=abc01.xyz.com;port=$port",'gvenkat','ganesh99') //

I want to be able to put the portnumber,hostname,username,password values in a header file and read it from there so that the values are not visible in the actual perl modules.

I'm fairly new to perl and any help would be appreciated.


FishMonger
Veteran / Moderator

Aug 4, 2016, 7:44 AM

Post #2 of 9 (2750 views)
Re: [gvenkat] Read from a header file like C [In reply to] Can't Post

Perl has many different modules available which gives you many different options for the desired config format such as CSV, XML, INI, JSON, YAML, and others. Did you have a specific format you wanted to use?


gvenkat
Novice

Aug 4, 2016, 8:24 AM

Post #3 of 9 (2744 views)
Re: [FishMonger] Read from a header file like C [In reply to] Can't Post

No. I just want it to be a perl file or a config file in the same directory my other perl programs are residing. So that they can read from this config file and give me the desired result.

I don't think it should be too complicated, But since i'm a newbie I'm not sure how to go about this.


FishMonger
Veteran / Moderator

Aug 4, 2016, 1:11 PM

Post #4 of 9 (2725 views)
Re: [gvenkat] Read from a header file like C [In reply to] Can't Post

What version of perl are you using and on which OS?

Also, is the script being used in a web environment?


(This post was edited by FishMonger on Aug 4, 2016, 1:16 PM)


gvenkat
Novice

Aug 4, 2016, 2:29 PM

Post #5 of 9 (2719 views)
Re: [FishMonger] Read from a header file like C [In reply to] Can't Post

I'm using perl version 5.12 in a Unix environment. No this script is not going to be in a web environment.

Just plain read from a config file on the actual programs that run to perform some data extracts.


FishMonger
Veteran / Moderator

Aug 4, 2016, 2:51 PM

Post #6 of 9 (2715 views)
Re: [gvenkat] Read from a header file like C [In reply to] Can't Post

Ok, I'm tied up in a meeting but will work up an example when I have some free time.


gvenkat
Novice

Aug 4, 2016, 3:03 PM

Post #7 of 9 (2713 views)
Re: [FishMonger] Read from a header file like C [In reply to] Can't Post

Ok. Thanks. No hurry, If you can give me an example by the weekend it should be fine.


BillKSmith
Veteran

Aug 6, 2016, 6:18 AM

Post #8 of 9 (2691 views)
Re: [gvenkat] Read from a header file like C [In reply to] Can't Post

We do not object to cross posting on other sites, but please tell us! I just discovered that kennethk (on perlmonks) has already provided much the same answer that I was working on.
Good Luck,
Bill


gvenkat
Novice

Aug 6, 2016, 7:36 AM

Post #9 of 9 (2687 views)
Re: [BillKSmith] Read from a header file like C [In reply to] Can't Post

It was just an oversight. Apologies. I tried to get as much input as possible.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives