Erlang/OTP Forums

Author Message

<  Yaws mailing list  ~  It looks like a string, it barks like a string

Guest
Posted: Mon May 05, 2008 9:46 pm Reply with quote
Guest
When trying to parse the parameters to a Form with action=POST I run into this strange behaviour:



crew(Arg, N) ->
Guest
Posted: Mon May 05, 2008 11:16 pm Reply with quote
Guest
On 5/5/08, Guido Witmond <guido@witmond.nl> wrote:
> When trying to parse the parameters to a Form with action=POST I run into
> this strange behaviour:
>
> crew(Arg, N) ->
> % Name = f("crew_~B", [N]),
> Name = lists:concat(io_lib:format("~s~B",
> ["crew_",N])),
>
> case yaws_api:getvar(Arg, Name) of
> {ok, Member} -> #crewmember{naam = Member};
> _ -> Name
> end.
>
> My initial guess was to generate key names with f(...) but that lead to this
> output where the case matches the _ clause and it shows up as
> [[99,114,101,119,95,"1"],
> [99,114,101,119,95,"2"]
>
> When I use the lists:concat it does match the {ok, Member} clause. It gives
> the expected:
> [{crewmember,"jan",undefined},
> {crewmember,"piet",undefined},
>
> What is going on here? When is a string a string?

io_lib:format() returns an iolist, not a string, and f() simply wraps
io_lib:format() so it also returns an iolist. You can wrap either with
a call to lists:flatten to get a string:

lists:flatten(io_lib:format("~s~B", ["crew_",N]))

--steve

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum