[erlang-questions] Basic questions, also related to yaws and mnesia

Chandru <>
Tue Oct 16 11:36:27 CEST 2007


On 16/10/2007, Berlin Brown <> wrote:
> I should probably move away from yaws for a sec and go over the
> basics, but I am really close to what I want to do.
>
> I have a record and a list of records, but I don't know the best ways
> to extract the data and show the data out of the record.
>
> For example, with this code; how would I iterate(map?) those links and
> display them.
>
> out(Args) ->
>         {ok, EntityLinks} = botlist_find_links:find_links(),
>         { html,
>                 yaws_api:f("~p", [EntityLinks])
>         }.
>
> This is the record.
> -record(entity_links, {main_url, url_title, keywords, rating,
> full_name, created_on}).
>

out(Args) ->
        {ok, EntityLinks} = botlist_find_links:find_links(),
        { html,
                [make_link(X) || X <- EntityLinks]
        }.

make_link(#entity_link{main_url = Url, url_title = Title}) ->
    io_lib:format("<a href=~s>~s</a>", [Url, Title]).

Or if you want to squeeze out every ounce of performance:
make_link(#entity_link{main_url = Url, url_title = Title}) ->
    ["a href=", Url, ">", Title, "</a>"].

cheers
Chandru



More information about the erlang-questions mailing list