<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Managing Application Configuration</title>
	<atom:link href="http://spawnlink.com/articles/managing-application-configuration/feed/" rel="self" type="application/rss+xml" />
	<link>http://spawnlink.com/articles/managing-application-configuration/</link>
	<description>Linking You to Erlang</description>
	<pubDate>Thu, 29 Jul 2010 20:02:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Witold Baryluk</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-10959</link>
		<dc:creator>Witold Baryluk</dc:creator>
		<pubDate>Wed, 12 Aug 2009 14:03:09 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-10959</guid>
		<description>It is very cool thing.

But sometimes file:consult/1 isn't enaugh, for example if you want to use, expression (like multiply something, or append list to another, or use list comprehension).

This snipet will do this:

eval(Filename) -&#62;
  {ok, B} = file:read_file(Filename),
  T = binary_to_list(B),
  {ok, Tokens, _EndLocation} = erl_scan:string(T),
  {ok, [Expression]} = erl_parse:parse_exprs(Tokens),
  Bindings = erl_eval:new_bindings(),
  {value, Value, _NewBindings} = erl_eval:expr(Expression, Bindings),
  {ok, Value}.

Use like eval("file.cfg");

example file.cfg:
{hosts, 
    [ {active, Host, 100} &#124;&#124; X &#60;- [a1,a2,a3,a4,a5] ] ++
    [ {passive, Host, 200} &#124;&#124; X &#60;- [p1, p2, p3, p4] ]
}.
{acl, [ {joe, md5("password') } ]}.


this is just example. You need to consider that users can write any expressions there (like erlang:halt() ).</description>
		<content:encoded><![CDATA[<p>It is very cool thing.</p>
<p>But sometimes file:consult/1 isn&#8217;t enaugh, for example if you want to use, expression (like multiply something, or append list to another, or use list comprehension).</p>
<p>This snipet will do this:</p>
<p>eval(Filename) -&gt;<br />
  {ok, B} = file:read_file(Filename),<br />
  T = binary_to_list(B),<br />
  {ok, Tokens, _EndLocation} = erl_scan:string(T),<br />
  {ok, [Expression]} = erl_parse:parse_exprs(Tokens),<br />
  Bindings = erl_eval:new_bindings(),<br />
  {value, Value, _NewBindings} = erl_eval:expr(Expression, Bindings),<br />
  {ok, Value}.</p>
<p>Use like eval(&#8221;file.cfg&#8221;);</p>
<p>example file.cfg:<br />
{hosts,<br />
    [ {active, Host, 100} || X &lt;- [a1,a2,a3,a4,a5] ] ++<br />
    [ {passive, Host, 200} || X &lt;- [p1, p2, p3, p4] ]<br />
}.<br />
{acl, [ {joe, md5("password') } ]}.</p>
<p>this is just example. You need to consider that users can write any expressions there (like erlang:halt() ).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: grantmichaels</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9677</link>
		<dc:creator>grantmichaels</dc:creator>
		<pubDate>Thu, 09 Jul 2009 22:13:59 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9677</guid>
		<description>It's awesome to see that you are planning to start blogging again!</description>
		<content:encoded><![CDATA[<p>It&#8217;s awesome to see that you are planning to start blogging again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitchell</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9644</link>
		<dc:creator>Mitchell</dc:creator>
		<pubDate>Thu, 09 Jul 2009 02:39:53 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9644</guid>
		<description>Ferd T-H,

Awesome! After I read about it more and find some time I'll update the post to reflect these findings. Thank you very much.</description>
		<content:encoded><![CDATA[<p>Ferd T-H,</p>
<p>Awesome! After I read about it more and find some time I&#8217;ll update the post to reflect these findings. Thank you very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ferd T-H</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9640</link>
		<dc:creator>Ferd T-H</dc:creator>
		<pubDate>Thu, 09 Jul 2009 00:18:34 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9640</guid>
		<description>To read form a proplist ([{key,Value}]), see the proplist module with the functions get_value/2 and get_value/3. They're going to do what you want without you needing to write anything.

1&#62; Conf = [{appname, "Hello"}, {user,"Ferd"}].
[{appname,"Hello"},{user,"Ferd"}]
2&#62; proplists:get_value(user,Conf).            
"Ferd"
3&#62; proplists:get_value(password, Conf, "Default if not found").
"Default if not found"

Check around the module for some other helpful functions to deal with proplists rather than writing them yourself.</description>
		<content:encoded><![CDATA[<p>To read form a proplist ([{key,Value}]), see the proplist module with the functions get_value/2 and get_value/3. They&#8217;re going to do what you want without you needing to write anything.</p>
<p>1&gt; Conf = [{appname, "Hello"}, {user,"Ferd"}].<br />
[{appname,"Hello"},{user,"Ferd"}]<br />
2&gt; proplists:get_value(user,Conf).<br />
&#8220;Ferd&#8221;<br />
3&gt; proplists:get_value(password, Conf, &#8220;Default if not found&#8221;).<br />
&#8220;Default if not found&#8221;</p>
<p>Check around the module for some other helpful functions to deal with proplists rather than writing them yourself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brendon Murphy</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9629</link>
		<dc:creator>Brendon Murphy</dc:creator>
		<pubDate>Wed, 08 Jul 2009 18:14:33 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9629</guid>
		<description>Thanks for sharing this.  Having spent most my time recently in Rails (or even just plain Ruby) I'm addicted to being able to use YAML for reading a config.  As I'm new to Erlang, this'll help fill the gap I'm sure.</description>
		<content:encoded><![CDATA[<p>Thanks for sharing this.  Having spent most my time recently in Rails (or even just plain Ruby) I&#8217;m addicted to being able to use YAML for reading a config.  As I&#8217;m new to Erlang, this&#8217;ll help fill the gap I&#8217;m sure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop &#8211; July 8, 2009 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9624</link>
		<dc:creator>Dew Drop &#8211; July 8, 2009 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Wed, 08 Jul 2009 14:56:27 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9624</guid>
		<description>[...] Managing Application Configuration (Mitchell Hashimoto) [...]</description>
		<content:encoded><![CDATA[<p>[...] Managing Application Configuration (Mitchell Hashimoto) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anselmo Silva</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9612</link>
		<dc:creator>Anselmo Silva</dc:creator>
		<pubDate>Wed, 08 Jul 2009 10:20:28 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9612</guid>
		<description>Tks, great stuff as usual.</description>
		<content:encoded><![CDATA[<p>Tks, great stuff as usual.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-07-08 &#171; Bloggitation</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9605</link>
		<dc:creator>links for 2009-07-08 &#171; Bloggitation</dc:creator>
		<pubDate>Wed, 08 Jul 2009 07:04:43 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9605</guid>
		<description>[...] Managing Application Configuration (tags: erlang programming)      Leave a Comment [...]</description>
		<content:encoded><![CDATA[<p>[...] Managing Application Configuration (tags: erlang programming)      Leave a Comment [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harish Mallipeddi</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9602</link>
		<dc:creator>Harish Mallipeddi</dc:creator>
		<pubDate>Wed, 08 Jul 2009 06:26:44 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9602</guid>
		<description>Good to see you writing again! I learnt a lot from your series of blog posts on OTP.</description>
		<content:encoded><![CDATA[<p>Good to see you writing again! I learnt a lot from your series of blog posts on OTP.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Lee</title>
		<link>http://spawnlink.com/articles/managing-application-configuration/#comment-9600</link>
		<dc:creator>James Lee</dc:creator>
		<pubDate>Wed, 08 Jul 2009 04:26:37 +0000</pubDate>
		<guid isPermaLink="false">http://spawnlink.com/?p=163#comment-9600</guid>
		<description>Thanks for this.  I'm working on my first little project in Erlang and was looking for some tips on how to store configuration.  I've been spoiled by http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html, but I think I can whip up a few more functions to add to your examples to get something comparable.</description>
		<content:encoded><![CDATA[<p>Thanks for this.  I&#8217;m working on my first little project in Erlang and was looking for some tips on how to store configuration.  I&#8217;ve been spoiled by <a href="http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html" rel="nofollow">http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html</a>, but I think I can whip up a few more functions to add to your examples to get something comparable.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
