File: consult without file part

I am writing an script that needs normal propolis as its input:

script "[{error_string, \" This is broken \ "}]"

all I want to do now is parse arbitrary strings in real proplies, usually I write this to a file and then continue to use the file: consult the file to get the values ​​- this is however a bit like top - so my question in how can I do the same, that is, parse the input string into proplist without sending the data to a file?

+3


source to share


2 answers


M1 = "[{error_string, \"This is broken\"}].",
{ok, S1, _} = erl_scan:string(M1),
erl_parse:parse_term(S1).

      

returns



{ok,[{error_string,"This is broken"}]}

      

+4


source


The easiest way to do this is to use erl_eval

as in Odobenus Rosmarus answer , even if it seems a little tricky. Just remember to put it .

at the end of your expression. You can read a little about this topic on the Erlang Central Wiki .



But if you are creating an escript to populate your application with parameters, I would look at a full size argument parser. I've used https://github.com/jcomellas/getopt before . The project is stable, with reasonably good documentation, and does what it needs to do. It requires little configuration, but the generated code remains readable.

+1


source