[EMAIL PROTECTED] wrote: > Hi all, newbie question: I've got this .pl that has variables hard > coded in it, and I need to draw these form a file instead... Here's > roughly what I've got, how can I get the variables from a file in > stead? > > my %ldap_hosts =("SOME_ENVIRONMENT_NAME" => "server.somename.org", > "ANOTHER_ENVIRONMENT_NAME" => > "another.server.somename.org"); > > So I've got this file /opt/stuff/config/conf.txt > and in it is an entry like: > > Host_Name: serverxyz > Port: 666 > > 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"; > > But where do I go from there? > > 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... Thanks! > Jason I don't know about the passwords, but I run an interanl setup which uses a basic file config to handle the keys and/or data as a Hash. For me it is of the form: key1 data1 key2 data2 .... keyn datan
I have a master setup which is always loaded and then depending on the script, it can have other values which it needs. By doing this I make changes to how processing goes on without having to make mods to the scripts. SO earlier in your script, have your hash defined and then pass to environ($MyHash) where it builds all the keys you need. For me I do a simple regex of /^\s*(\S+)\s+(.+)/ which puts my key in $1 and my data in $2. In fact I pass another param telling me whether this is the first pass( Master ini ) or second to check on any individual script ini. Wags ;) ******************************************************* This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ******************************************************* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>