Read a configuration file: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
|||
Line 3,982: | Line 3,982: | ||
[1] => Harry Barber |
[1] => Harry Barber |
||
)</pre> |
)</pre> |
||
=={{header|Picat}}== |
|||
<lang Picat>go => |
|||
Vars = ["fullname","favouritefruit","needspeeling","seedsremoved","otherfamily"], |
|||
Config = read_config("read_a_configuration_file_config.cfg"), |
|||
foreach(Key in Vars) |
|||
printf("%w = %w\n", Key, Config.get(Key,false)) |
|||
end, |
|||
nl. |
|||
% Read configuration file |
|||
read_config(File) = Config => |
|||
Config = new_map(), |
|||
Lines = [Line : Line in read_file_lines(File), Line != [], not membchk(Line[1],"#;")], |
|||
foreach(Line in Lines) |
|||
Line := strip(Line), |
|||
once( append(Key,[' '|Value],Line) ; Key = Line, Value = true), |
|||
if find(Value,",",_,_) then |
|||
Value := [strip(Val) : Val in split(Value,",")] |
|||
end, |
|||
Key := strip(to_lowercase(Key)), |
|||
Config.put(Key,Value) |
|||
end.</lang> |
|||
{{out}} |
|||
<pre>fullname = Foo Barber |
|||
favouritefruit = banana |
|||
needspeeling = true |
|||
seedsremoved = false |
|||
otherfamily = [Rhu Barber,Harry Barber]</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |