Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 14:03
Show Gist options
  • Save alco/467097bb3f867682f41f to your computer and use it in GitHub Desktop.
Save alco/467097bb3f867682f41f to your computer and use it in GitHub Desktop.
%%!
main([Path]) ->
%Path = get_path(),
{ok, ExprBin} = file:read_file(Path),
% confirm it is UTF-8
io:format("~w~n", [ExprBin]),
Expr1 = unicode:characters_to_list(ExprBin),
Expr2 = binary_to_list(ExprBin),
io:format("~w~n", [Expr1]),
io:format("~w~n", [Expr2]),
{ok, Toks, _} = erl_scan:string(Expr1),
{ok, Ast} = erl_parse:parse_exprs(Toks),
{value, Result, _} = erl_eval:exprs(Ast, []),
io:format("~p~n", [Result]).
λ echo '"héllo".' >test.txt | escript priv/erlang/eval.erl test.txt
[34,104,233,108,108,111,34,46,10]
[34,104,195,169,108,108,111,34,46,10]
"hlo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment