Search code examples
erlangerlang-shell

Disable pretty writing of strings to file


I can use shell:strings(false) to disable the pretty writing of strings in shell.

I am saving a list of integers to file and need the numbers, not string. eg.

[[8,1,3,100,35,25,10,20,25],"+\v%"],

should have [57,63,11] at the end instead.

63> "9?\v".
[57,63,11]

How do I change this?

generate(Num) -> 
  Result = generate(Num, []),
  Dedup = deduplicated(Result),
  file:write_file("./react/src/Data/gennedmons", io_lib:fwrite("~p.\n", [Dedup])),
  Dedup.

I have tried writin with ~w, too. No apparent effect.


Solution

  • ~w seems to do what you want in this simple test. Does this not match what you're doing?

    1> file:write_file("foo", io_lib:fwrite("~p~n", ["9?\v"])).
    ok
    2>
    [2]+  Stopped                 erl
    ~ $ cat foo
    "9?\v"
    ~ $ fg
    erl
    
    2> file:write_file("foo", io_lib:fwrite("~w~n", ["9?\v"])).
    ok
    3>
    [2]+  Stopped                 erl
    ~ $ cat foo
    [57,63,11]
    ~ $