beginner question

2 views
Skip to first unread message

Allan Streib

unread,
Nov 22, 2010, 9:10:24 PM11/22/10
to erlan...@googlegroups.com
Thought I'd ask the group a beginner question. I'm starting my first "real" project using Erlang.

Part of the project involves importing some data from text files into a database. I have a property list that contains, for each different file type, the expected fields that should be in the "header" (first line) of the file. So I have a function that looks like this:

get_header(Type) ->
Headers = [
{cpu_usage, ["host", "user_pct", "system_pct", "iowait_pct", "idle_pct", "timestamp"]},
{smb_users, ["host", "num_connections", "timestamp"]},
{tot_bytes, ["host", "num_kbytes", "timestamp"]},
{tot_files, ["host", "num_files", "timestamp"]},
... etc ...
],
proplists:get_value(Type, Headers).

To handle new formats, I pretty much just need to add the expected fields to this list. What's a good way to do that so that the program does not need to be recompiled? I was thinking of using an ets table that I load either in program initialization or lazy-style on the first call to the function. Is this the right approach?

Thanks,

Allan

Martin Logan

unread,
Nov 23, 2010, 11:20:18 AM11/23/10
to erlan...@googlegroups.com
Allan, the best way to do this is to use config. Take a look at the application module for more details. A config file, which contains an erlang prop list, can be supplied via the -config option to erl. The application module is how you would access it. 

Cheers,
Martin
--
Martin Logan
Erlang & OTP in Action (Manning) http://manning.com/logan

Reply all
Reply to author
Forward
0 new messages