473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how to create a config file that a perl script will use.

154 100+
Basically i am trying to make a config file

which will contain to sets of paths
for e.g - this file is called config.pl

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. #Path1
  4. $sourcedir1 = '/home/test/srcdir1';
  5. $destdir1 = '/home/test/srcdir1';
  6.  
  7. #Path2
  8. $sourcedir2 = '/home/test/srcdir2';
  9. $destdir2 = '/home/test/srcdir2';
  10.  
Now the actual script file is called sort_script.pl
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. require "include.pl";
  4.  
  5. use File::Copy;
  6.  
  7.  $sourcedir1 = $src;
  8.  $destdir1 =$dest
  9. &myscript("$sourcedir1", "$destdir1");
  10.  
  11. $sourcedir2 = $src;
  12.  $destdir2 =$dest
  13. &myscript("$sourcedir2", "$destdir2");
  14. sub myscript {
  15. ###### Actual script code here #######
  16. code uses throught out the script $src and $dest variables
  17. but needs to be defined outside sub area
  18. }
  19.  
Now how would i have the code run for path 1, run the code then when finished go to path 2 and run the code?

So how would i be able to run both paths from the config file.


Could somebody help me with this please.
Nov 1 '07 #1
3 5480
numberwhun
3,509 Expert Mod 2GB
First, why create a config file as a perl script? Why not create a text file containing 2 columns. One that is a variable and one that is the value.

ie:
Expand|Select|Wrap|Line Numbers
  1. <name>     <value>
  2. <name>     <value>
  3. .
  4. .
  5. .
  6.  
The first column (<name>) is more of a reference for you so you know what it is. You would use a split to split each line up and grab the second field.

Second, you really need to "use strict" and "use warnings" or nobody will touch your code.

Regards,

Jeff
Nov 1 '07 #2
KevinADC
4,059 Expert 2GB
Why are you using a seperate file for the directory information?

Either use a hash or an array in the config file and loop through the hash or array in your main script.
Nov 2 '07 #3
numberwhun
3,509 Expert Mod 2GB
Why are you using a seperate file for the directory information?

Either use a hash or an array in the config file and loop through the hash or array in your main script.
Well, one reason (and this is lessons learned) is that its always better to have a config file to edit with the directories in it, then to have a script that has to be edited. Once scripts are in Production they shouldn't be edited. The config file, however, is one place to edit without it being your script.

It was just a thought.

Jeff
Nov 2 '07 #4

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

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
11
by: Paul D.Smith | last post by:
Can Python create a variable "on-the-fly". For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ....to output... the grouch
5
by: qqcq6s59 | last post by:
Hi all I am a newbie and I just saw a ongoing thread on Fileprocessing which talks abt config parser. I have writen many pyhton program to parse many kind of text files by using string module and...
10
by: robwharram | last post by:
Hi, I'm quite frustrated in the fact that I can't even display a simple "Hello World" message on .Net. I've been through all of the groups and searched all over the place and haven't been able...
3
by: Madhu | last post by:
All, New to DB2 environment. Can someone share a script that can be used to a create a DB2 UDB database manually. I am trying to create a database on Linux, single partition. Thanks Madhu
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
16
by: Mich | last post by:
Hi, i'm building an web application for anonymous users. They can take a look in the website, nothing more. In order to perform other actions, the anonymous user must be logged. So i create an...
1
by: Tension | last post by:
Hi, I am trying to run a Tornado simulator with Perl. The command line in an ordinary Windows command window looks like this: "C:\Tornado\target\config\simpc\vxWorks.exe /r32000000" Which I...
5
by: monsteriffic | last post by:
I'm totally new here. Can someone provide me a short Perl script and its corresponding config file so that i can compare and base on it as my pattern? I appreciate the help, thanks. I included a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.