0

Have a look at my index.yaws file below

<html>
<body>
    <h4>Data:</h4>

    <erl>
        out(Arg) -> 
            Data = utilities:get_raw_data(),
            {html, io_lib:format("~p", [Data])}.        
    </erl>    

    <erl>
        out(Arg) -> 
        Data = utilities:get_raw_data(),
        lists:foreach(fun(X) -> {Id, Fname, Lname} = X, io:format("ID: ~p ", [Lname]) end, Data).
    </erl>

</body>  
</html>

The first part of the code runs correctly producing output such as

[{3,"Matt","Williamson3"}, {2,"Matt","Williamson2"}, {1,"Matt","Williamson"}]

There is no error on the second part, but the web page remains blank. I believe the section

io:format("ID: ~p ", [Lname]) 

doesn't print out to the browser.

What do I get to change in order for it to work?

Robert
  • 19,800
  • 5
  • 55
  • 85
Benda
  • 110
  • 3
  • 14

1 Answers1

2

Try this instead of the foreach line: (untested)

    {html, lists:map(fun(X) -> {Id, Fname, Lname} = X, io_lib:format("ID: ~p ", [Lname]) end, Data)}.

That is, instead of printing using io:format, return the data in a {html, Iodata} tuple, as in the first <erl> block.

legoscia
  • 39,593
  • 22
  • 116
  • 167
  • 1
    Thank you! That solution works OK. wanted to vote it up but I dont have the minimum 15 points needed to do the necessary :-) – Benda May 08 '13 at 12:01
  • By the way this is what I wanted to do: out(Arg) -> Data = utilities:get_raw_data(), {html, lists:map( fun(X) -> {Id, Fname, Lname} = X, io_lib:format("~s", [""]) end, Data) }.
    " ++ Lname ++ "" ++ Fname ++ "
    – Benda May 08 '13 at 12:01
  • Good to hear it works! You can "accept" the answer even if you have less than 15 reputation points. – legoscia May 08 '13 at 12:28