Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Config file help

by johnajb (Novice)
on Jun 23, 2005 at 22:04 UTC ( #469542=perlquestion: print w/ replies, xml ) Need Help??
johnajb has asked for the wisdom of the Perl Monks concerning the following question:

HI There, I would like to use a webpage to configure a flat text file that I am using as a config file for an application I have written. How would I create this form to add the config values with using a web server. I would like to have a link and launch this web page locally. Is there any way to do this? the config file is located on a windows 2003 server.

Replies are listed 'Best First'.
Re: Config file help
by kyoshu (Curate) on Jun 23, 2005 at 22:21 UTC
    to edit some file via browser you will need to be able to edit it with your http deamon users rights and submit some form with textfield or textarea, so you can use popular CGI module, and depending on your config file you can rewrite it with data entered into form or use for example Config::IniFiles module (for ini files) etc...
Re: Config file help
by Adrade (Pilgrim) on Jun 23, 2005 at 23:10 UTC
    For config stuff like that, I think DB_File comes in handy... you could easily, from within both programs, do this:
    #!/usr/bin/perl use DB_File; use CGI 'param'; print "Content-type: text/plain\n\n"; my $filename = '/path/to/database'; tie %hash, "DB_File", $filename, O_RDWR|O_CREAT; print 'thisvar: ', $hash{'thisvar'}, "\n"; $hash{'thisvar'} = param('webvar'); # modifies from form value untie %hash;
    Of course, in your non-CGI program, you wouldnt be loading in the CGI module.

    Naturally, you could also do something like this:
    $filename = '/path/to/config/file'; open(CONF,"<$filename"); while(<CONF>){ chomp; my ($q, $w) = split(/\t/,$_,2); $config{$q} = $w; } close(CONF); $config{'variable'} = 'new contents'; open(CONF, ">$filename"); print CONF "$_\t$config{$_}\n" for keys %config; close(CONF);

    Good luck,

    Impossible! The Remonster can only be killed by stabbing him in the heart with the ancient bone saber of Zumakalis!

Re: Config file help
by gellyfish (Monsignor) on Jun 23, 2005 at 23:52 UTC

    This is almost certainly trivial to most people here, except for two things - you haven't shown us the format of the config file you want to manipulate and you haven't shown us the code you are having trouble with.


Re: Config file help
by tcf03 (Deacon) on Jun 24, 2005 at 00:38 UTC
    I just added some code to the Code Catacombs --> notes.cgi. That and the cgi documentation should give you a start.

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson
Re: Config file help
by mikeraz (Friar) on Jun 24, 2005 at 00:19 UTC

    Are you trying to create a collection of key value pairs? Something like:

    DataDir = UserInputDD RefreshInterval = UserInputRI WhatEverVar = UserInputWEV
    In that case you could do a standard form and write out the config file with the results.

    Michael "too lazy today to cook up an expample " R

    Be Appropriate && Follow Your Curiosity
Re: Config file help
by stonecolddevin (Vicar) on Jun 24, 2005 at 06:32 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://469542]
Approved by moot
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2016-06-28 23:42 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (364 votes). Check out past polls.