On Tue, 17 Aug 2004 [EMAIL PROTECTED] wrote:
So how do I read this in? I know I need to open the file, etc etc etc.. I was thinking I need:
open(CONF, ">$CONFFileName") || die "ERROR: could not open $CONFFileName, $!\n";
Opening a file with the '>' means "overwrite the existing contents".
This probably isn't what you meant :-)
Turn that into a '<' to read in from the file, as
open CONF, "<$conf_file" or die "Couldn't read from $conf_file: $!";
Basically, this script was written by someone else, and they built it to read all commmand line args instead of reading from a conf file... I need to change this puppy to read from a file.... That way I can cron it up and don't have to manually enter all the stuff from command line... Yeah yeah yeah, I could pass the info in with cron also, but I don't want server names, IDs, and passwords sitting in plain text in my crontab...
Well, you could have your crontab launc /usr/local/bin/foo, where the file in /usr/local/bin/foo is a shell script like
#!/bin/sh
/path/to/other/thing --arg1 --arg2 --arg3=whatever etc
and then just lock down permissions on that file...
...but that's probably a band-aid that doesn't fix the real problem.
Can you paste a several-line snippet of the config file to the list, with notes about what data elements you need pumped into which variables?
Also, are you bound to using the config file format you sent earlier? If you can use the Windows .ini file format, the Config::IniFiles module makes working with them very easy:
Config file:
[prod] ORACLE_HOME=/path/to/oracle/prod ORACLE_SID=prod_sid [test] ORACLE_HOME=/path/to/oracle/test ORACLE_SID=test_sid [dev] ORACLE_HOME=/path/to/oracle/dev ORACLE_SID=dev_sid
Perl code:
# Make the module available use Config::IniFiles;
# now nab the entire config file contents into the %ini hash my $ConfigFile = "/path/to/inifile/inifile"; tie my %ini, 'Config::IniFiles', (-file => $ConfigFile);
# now grab the relevent section into it's own hash, # we're assuming that it's "prod" for this example my %Config = %{$ini{"prod"}};
# now we have access to our keys in the hash print "Oracle home is $Config{ORACLE_HOME}"; print "Oracle SID is $Config{ORACLE_SID}";
More info:
<http://perlmonks.thepen.com/35967.html> <http://search.cpan.org/~wadg/Config-IniFiles-2.38/IniFiles.pm>
Parsing files like this isn't terribly hard to sort out by hand, but a module like this makes it so easy that you might as well just save yourself the effort, ya know? :-)
-- Chris Devers [EMAIL PROTECTED] http://devers.homeip.net:8080/blog/
np: 'Tin Pan Alley' by Stevie Ray Vaughan from 'In The Beginning'
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>