发表时间:2012-05-12
< > 猎头职位: 北京: 【北京】数据分析高级工程师/经理
相关文章:
Erlang开发建议(杂记版)
Erlang类型及函数声明规格
List杂记
推荐群组: struts2
更多相关推荐
Erlang
Erlang 实践杂记
一、列表、字符串相关
1、场景描述
当下,Erlang和php交互,用mochiweb和ibrowse的方式比较多,ibrowse 需要发送url给php,url为字符串。若需要string:concat() 的变量不为string类型,就需要进行转化。前提是,Erlang处理中,多为二进制。
2、问题
1> B = <<"test">>.
<<"test">>
2> S = binary_to_term(B).
** exception error: bad argument
in function binary_to_term/1
called as binary_to_term(<<"test">>)
上例,视图将binary类型的数据转换成term数据,出现 bad argument 错误,悲剧。
3> L = binary_to_list(B).
"test"
貌似是可以了,但是,使用string:concat("my", L) 时会再一次发生悲剧,这个时候的L是list类型,而string:concat 要求的参数是string类型,所以当然会悲剧。
3、解决
1> B = <<"test">>.
<<"test">>
2> L = binary_to_list(B).
"test"
3> S = lists:flatten(L).
"test"
这个时候,再去看看string:concat("my", S) ,OK,搞定。
4、总结
http://www.erlang.org/doc/man/lists.html#flatten-1
flatten(DeepList) -> List
Types:
DeepList = [term() | DeepList]
List = [term()]
Returns a flattened version of DeepList.
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
Java开发新方式:专注UI,快速开发!
< > 猎头职位: 北京: 【北京】数据分析高级工程师/经理
相关文章:
Erlang开发建议(杂记版)
Erlang类型及函数声明规格
List杂记
推荐群组: struts2
更多相关推荐
Erlang
Erlang 实践杂记
一、列表、字符串相关
1、场景描述
当下,Erlang和php交互,用mochiweb和ibrowse的方式比较多,ibrowse 需要发送url给php,url为字符串。若需要string:concat() 的变量不为string类型,就需要进行转化。前提是,Erlang处理中,多为二进制。
2、问题
1> B = <<"test">>.
<<"test">>
2> S = binary_to_term(B).
** exception error: bad argument
in function binary_to_term/1
called as binary_to_term(<<"test">>)
上例,视图将binary类型的数据转换成term数据,出现 bad argument 错误,悲剧。
3> L = binary_to_list(B).
"test"
貌似是可以了,但是,使用string:concat("my", L) 时会再一次发生悲剧,这个时候的L是list类型,而string:concat 要求的参数是string类型,所以当然会悲剧。
3、解决
1> B = <<"test">>.
<<"test">>
2> L = binary_to_list(B).
"test"
3> S = lists:flatten(L).
"test"
这个时候,再去看看string:concat("my", S) ,OK,搞定。
4、总结
http://www.erlang.org/doc/man/lists.html#flatten-1
flatten(DeepList) -> List
Types:
DeepList = [term() | DeepList]
List = [term()]
Returns a flattened version of DeepList.
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
Java开发新方式:专注UI,快速开发!