Google Groups

Re: beginner question

Martin J. Logan Nov 23, 2010 8:20 AM
Posted in group: erlangcamp
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. 


On Mon, Nov 22, 2010 at 8:10 PM, Allan Streib <> wrote:
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?



Martin Logan
Erlang & OTP in Action (Manning)