Anyone have a good JSL .ini file reader?I'm imagining
[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString
y=28
becoming
[
"Thing1"=>
["x"=>14, //not sure if this should be a number or string
"y"=>"String",
"z"=>"..."],
"Thing2"=>
["x"=>"DifferentString",
"y"=>28]
]
Automation and ScriptingRe: Anyone have a good JSL .ini file reader?I think I did something like this when I wanted to use same config file in python and JMP, but gave up dont remember why. But I had to do some parsing for Minitab MAC files and the same idea might work here.
Below is modified script to fit this type of strings. Might require adding Trim Whitespace:
Names Default To Here(1);
config_file = "[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString
y=28
";
aa_ini = Associative Array();
cur_key = "";
For Each({line}, Words(config_file, "\!N"),
If(Ends With(line, "]") & Starts With(line, "["),
new_key = Word(1, line, "[]");
aa_ini[Word(1, line, "[]")] = Associative Array();
cur_key = new_key;
,
{key, value} = Words(line, "=");
//string conversion.. expect everything to be numbers and then try to convert
new_value = If(IsMissing(num(value)),
value,
num(value)
);
aa_ini[cur_key][key] = new_value;
);
);
show(aa_ini);<BR /><BR />aa_ini = ["Thing1" => ["x " => 14, "y " => " String", "z " => " ..."], "Thing2" => ["x" => "DifferentString", "y" => 28]];Re: Anyone have a good JSL .ini file reader?nice! It does need trim for key and value.
config_file =
"[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString with space
y=28
";
aa_ini = Associative Array();
cur_key = "";
For Each( {line}, Words( config_file, "\!N" ),
If( Ends With( line, "]" ) & Starts With( line, "[" ),
new_key = Word( 1, line, "[]" );
aa_ini[Word( 1, line, "[]" )] = Associative Array();
cur_key = new_key;
,
{key, value} = Words( line, "=" );
//string conversion.. expect everything to be numbers and then try to convert
new_value = If( Is Missing( Num( value ) ),
Trim( value ),
Num( value )
);
aa_ini[cur_key][Trim( key )] = new_value;
)
);
Write( As JSON Expr( aa_ini ) );
Move those .ini files into the current century!
{"Thing1":{"x":14,"y":"String","z":"..."},"Thing2":{"x":"DifferentString with space","y":28}}
Sometimes it is hard to tell if JSON is a step forward or backwards.
Re: Anyone have a good JSL .ini file reader?100% agree than XML and JSON and dumped Associative Arrays are not intended to be edited in notepad. And it does not always make sense to write your own editor, so .INI files still have their place.