mnesia primary key creation

Thomas Lindgren thomasl_erlang@REDACTED
Tue Jul 4 23:57:51 CEST 2006



--- Ulf Wiger <ulf@REDACTED> wrote:

> Den 2006-07-04 21:31:26 skrev Roberto Saccon
> <rsaccon@REDACTED>:
> 
> > I liked the cheap solution:
> >
> >   oid() -> {node(), erlang:now()}.
> >
> > but how can I turn erlang:now() into a String ??
> (which probablly
> > won't look very URL-friendly)
> >
> > I thouhgt of turing it into a list, then into a
> binary, then base64
> > encoding it, but
> >    list_to_binary(tuple_to_list(erlang:now()))
> > does not work.
> 
> Well, for example:
> 
> 1> {Node,{MS,S,US}} = {node(), erlang:now()}.
> {nonode@REDACTED,{1152,47770,297000}}
> 2>  
>
list_to_binary([atom_to_list(Node),"-",integer_to_list(MS),"-",integer_to_list(S),"-",integer_to_list(US)]).
>
<<110,111,110,111,100,101,64,110,111,104,111,115,116,45,49,49,53,50,45,52,55,55,55,48,45,50,57,55,48,...>>
> 3> binary_to_list(v(2)).
> "nonode@REDACTED"

Or, a bit easier on the eyes (though perhaps a bit
more expensive):

fmt_oid({Node, {MS, S, US}}) ->     
  list_to_binary(
     io_lib:format("~w-~w-~w-~w", [Node, MS, S, US])).

Best,
Thomas


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list