By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,693 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,693 IT Pros & Developers. It's quick & easy.

How can i create a config file?

P: 3
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 simple Factorial program (perl script) below with output to be printed in a text file..

Expand|Select|Wrap|Line Numbers
  1. $out="C:/0718/";
  2. print "Please specify what type of file you want to create :   ";
  3. chop ($inp=<STDIN>);
  4. print "What number to factor ? :  ";
  5. chop ($num=<STDIN>);
  6. open OUT, ">$out$inp" or die "Cannot open $out for write :$!";
  7.  
  8. $j=1;
  9. for ($i=1;$i<=$num;$i++)
  10.  
  11. {$j=$j*$i;
  12. print OUT "$j \t$i\n";}
  13. print OUT"The factorial of $num is $j \n";
  14.  
  15. print "Ok you can now check $out$inp \n";
  16.  
Thanks very much!

Monster
Jul 19 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
First, the use of code tags is required in the forums. Please use them to surround any and all code that you place in your posts. This is your warning.


As for your request, this is a learning forum, not a scripting service. If you are just wanting someone to write the script for you, then please feel free to post a job opening in the Jobs forum and hopefully someone will take it if the pay is right.

Otherwise, you can post the code you have tried in order to do what you ask, if it isn't working, and we can assist you in getting it working, all the while, you can learn some Perl.

Also, what does the factorial script have to do with your request?

Regards,

Jeff
Jul 19 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
Do you have something that needs to read/write a configuration file? There are modules like Config::General and Config::Simple for that purpose but I am not sure if you mean an actual configuration file or something else. It is also inappropriate to PM members seeking personal assistance or quicker than normal replies to your questions. Makes me suspicious that this is school/class work, which is not allowed to be posted here.
Jul 19 '08 #3

P: 3
First of all, thanks for the responses. Sorry for the confusion though.. I just want to know what does a config file do within a Perl script. I know this is something that a programmer can edit without creating any problem on the actual script? The reason I provided the simple factorial program is for me to know how to link a config file there. Yes Kevin, i think I need an actual config file for that simple script. Later on, I can do it myself once I got familiar on how the config file works against it.

Thanks Guys.

Monster
Jul 20 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
First of all, thanks for the responses. Sorry for the confusion though.. I just want to know what does a config file do within a Perl script. I know this is something that a programmer can edit without creating any problem on the actual script? The reason I provided the simple factorial program is for me to know how to link a config file there. Yes Kevin, i think I need an actual config file for that simple script. Later on, I can do it myself once I got familiar on how the config file works against it.

Thanks Guys.

Monster
You are correct! A config file is a place to put values that may or do change. That way, you can change them at will without having to change the script. The more complex your script is, the less you really want to edit it.

The format of the config file is up to you but there are modules (as Kevin pointed out) to process them. One module that we use where I work is called "Config::Scoped". Its a rather complex module, but the possibilities with it will amaze you. Personally, if you are just beginning with config files, the modules Kevin mentioned would be better. Or, if you wish, you can process them yourself, as I have done many times.

Regards,

Jeff
Jul 20 '08 #5

P: 3
Thanks Jeff, i'll take your advice. i will ask questions again once I bumped into an issue.
Jul 22 '08 #6

Post your reply

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