Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Best way to use configuration

37 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 4, 2017, 8:14:06 AM12/4/17
to
I am writing an application to store system statistics in a database.
But I do not want to have the database hard coded in the script. What
is the best way to store the database to use in a configuration file?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Gerald Lester

unread,
Dec 4, 2017, 9:56:38 AM12/4/17
to
On 12/04/2017 07:07 AM, Cecil Westerhof wrote:
> I am writing an application to store system statistics in a database.
> But I do not want to have the database hard coded in the script. What
> is the best way to store the database to use in a configuration file?

Which OS?


--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Cecil Westerhof

unread,
Dec 4, 2017, 11:14:07 AM12/4/17
to
Gerald Lester <Gerald...@KnG-Consulting.net> writes:

> On 12/04/2017 07:07 AM, Cecil Westerhof wrote:
>> I am writing an application to store system statistics in a database.
>> But I do not want to have the database hard coded in the script. What
>> is the best way to store the database to use in a configuration file?
>
> Which OS?

I am using Linux, but I prefer to write my scripts operating system
independent.

Brad Lanam

unread,
Dec 4, 2017, 11:50:33 AM12/4/17
to
Sort of depends on what kind of speed and access you want to
the data.

If you want one of /simple/user editable/, I would recommend you write it
out to a file as a tcl script that sets a dictionary variable.

set loadeddata {
item1 {model toyota color orange}
item2 {model vw color silver}
}

Then you just source the script to load it in.

I use a format like above and write to the file using relative record numbers
in order to keep it up to date.

There are gdbm style databases ( http://wiki.tcl.tk/38656 ) - random access,
on disk.

sqlite ( bundled with Tcl ) - in memory, writes to disk.

More: http://wiki.tcl.tk/3114

Gerald Lester

unread,
Dec 4, 2017, 1:00:25 PM12/4/17
to
On 12/04/2017 10:13 AM, Cecil Westerhof wrote:
> Gerald Lester <Gerald...@KnG-Consulting.net> writes:
>
>> On 12/04/2017 07:07 AM, Cecil Westerhof wrote:
>>> I am writing an application to store system statistics in a database.
>>> But I do not want to have the database hard coded in the script. What
>>> is the best way to store the database to use in a configuration file?
>>
>> Which OS?
>
> I am using Linux, but I prefer to write my scripts operating system
> independent.
>

Well, on all of the OSes except windows, normally you would either have
a file anmed ~/.myapp or a directory by that name with files in it. You
can either use the inifile package from TclLib
(http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/inifile/ini.html)
or just put out a file with a dictionary or [array get] and read it back
in and set the dictionary to the contents or do [array set] on the contents.

On Windows, the proper way is to stick it in the registery.
0 new messages