473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Taking input from configuration file in perl

40 New Member
Hi All,

I have a perl code which use a server ip and password for execution. Now i want to deploy this code on many servers. Instead of changing the ip & password values in all the perl code on all servers, i want to feed the input to the perl code through a (config) file. Sometimes the passwords may change on the server, i dont want to go into the code and change it. Just make a small modification in the config file and thats it. Can anybody help me how can i do that? Which perl module is needed for the same?

Thanks in advance for your help.

Cheers,
Amit
Aug 17 '07 #1
4 1938
numberwhun
3,509 Recognized Expert Moderator Specialist
I don't know about modules, but I can tell you an easy way to do it without modules.

Create your config file with two columns. the first column is the parameter and the second its value. I typically space separate them.

Now, the config file will always have the values in the same order, so you can open the file so it has a file handle, then do something like this to read the parameters:

Expand|Select|Wrap|Line Numbers
  1. open(CONFIG,"<$myfile.config")|| die "Can't open config file\n";
  2.  
  3.  
  4. $config_rec = <CONFIG>;
  5. chomp($config_rec) ;
  6. ($param1, $value1) = split(/\s+/, $config_rec);
  7.  
  8. $config_rec = <CONFIG>;
  9. chomp($config_rec) ;
  10. ($param2, $value2) = split(/\s+/, $config_rec);
  11.  
  12. $config_rec = <CONFIG>;
  13. chomp($config_rec) ;
  14. ($param3, $value3) = split(/\s+/, $config_rec);
  15.  
  16.  
That is a quick easy way that I have used to do read in the configuration files values. Hope this helped.

Regards,

Jeff
Aug 17 '07 #2
sainiamit25
40 New Member
Hi Jeff,

Thanks very much. i will try your sugegstion.

Cheers,
Amit
Aug 17 '07 #3
sainiamit25
40 New Member
HI Jeff,

I am not able to open the config file. I made myfile.config in /usr/local and put in the values as:
a 21
b 23
c 44
but when i copy paste ur code in the perl script, it is not able to open the file. KIndly suggest

Cheers,
Amit
Aug 17 '07 #4
sainiamit25
40 New Member
Sorry Jeff, there we a typo at my end..

Cheers,
Amit
Aug 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
11044
by: Don | last post by:
I just put up php.ini-recommended as php.ini in the server-side working directory where my php scripts are located. The file has "magic_quotes_gpc" set to "Off", but when I test it within my php...
1
4180
by: Dietrich | last post by:
Hi. I can't reread a file handle after I have copied it on another file handle for output. Here is the code snippet. Please let me know if you need more. Lines 26 & 27 are my attempts to get...
1
4136
by: ulloa | last post by:
Hi. My name is Randall and I am from Costa Rica. I have a little problem. I did an application using Perl, DBI and DBI::Oracle, and now I have to upload my application in an Unix server. The...
2
1875
by: championsleeper | last post by:
we have a system that recives plain text files from numerous external sources (database and others). our system recieves the information and then processes it. each line in the input file is a...
1
1784
by: Larry Snyder | last post by:
I zipped up my website from one server and would like to move it to another hosting company. Where in the tree are the configuration files for SQL kept? I see a file called database which is a...
5
3161
by: oaktown | last post by:
Running two input forms on the same page, one php and the other (the one I would like to create) to be written in perl. The idea is to accept an input from a perl script, then pass that input to two...
2
3893
by: Killer42 | last post by:
The Input #1 statement simply reads in one line from a text file (in this case you INI file) and places the values from it into one or more variables. So what you are reading in this statement is...
3
1692
by: markoj | last post by:
hi i HAVE WRITTEN A perl script that will search a file and print output I have created a simple html doc i want to be able to click a link and it will print the output in of a specific file so i...
2
1465
by: hutch75 | last post by:
Hi folks, I've been dead-ending on this issue, and I'm dusting off my brain to re-engage with Perl, so pls bear with me. Here's an example of what I'm trying to accomplish, have tried several...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.