Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Config file help

by Adrade (Pilgrim)
on Jun 23, 2005 at 23:10 UTC ( #469557=note: print w/ replies, xml ) Need Help??


in reply to Config file help

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,
  -Adam

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


Comment on Re: Config file help
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2015-07-06 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (72 votes), past polls