R List,
I'm writing a tcl/tk gui tool to wrap around RMySQL for some co-workers.
One function is to be able to add, modify, and remove entries to my.cnf, which
is where RMySQL stores database connection information in the following format:
[connection_name]
# comment
user = $username
password = $password
host = $hostname_or_ip
database = $which_database_to_use
I'm seeking advice as to a good way to read and write to this file.
Since I'm assuming that I will control the format of the entries via the
interface I provide to the users, I could simply use scan() to read the contents
of my.cnf into a list and then perhaps remunge them into an array. I know that
user-specified (non-default) entries will start with element 8 of the resulting
list, and I know each connection specification will consist of six elements in a
prescribed order.
The problem is, I do not want to assume that the users will not ever modify
my.cnf. They can create a valid (as far as RMySQL is concerned) config file
that will still break my application.
I could include a perl script to handle parsing my.cnf using multiline sed, but
that seems to be a possibly unnecessary level of complexity. A conditional
statement with a regex, e.g. "$user = $_ if s/user = //; is how I might do
this in perl.
Any advice from more seasoned coders would be greatly appreciated.
Thanks,
Pete
---------------------------------
Food fight? Enjoy some healthy debate
[[alternative HTML version deleted]]