Converting a string to integer

Greg Perry Greg.Perry@REDACTED
Tue Jun 2 01:32:40 CEST 2009


Ok I have another weird problem.  I have a file that contains a single
line that is a large number.  The file is read using read_file with the
second element of the tuple extracted:

myfile.txt:
123456

element(2,file:read_file("myfile.txt")).
<<"123456"...>>

Why don't this work?

io_lib:fread("~d", element(2,file:read_file("myfile.txt"))).
{error,{fread,integer}}

What would the easiest way be to extract a single line from a file and
convert it to an integer (for example the second element from a tuple
that read_file is assigned to)?

Thanks in advance

Greg








More information about the erlang-questions mailing list