[erlang-questions] string to tupple ?

info info@REDACTED
Sun Jun 20 23:42:11 CEST 2010


Why do you suspect I don't use a mysql driver ?
Data format is independant of the drivers. 
John

If you want to be more formal about it, both neotoma and leex/yecc
would make short work of that format.  Just out of curiosity, any
reason why you can't use a mysql driver for Erlang (instead of going
to the trouble of parsing)?

Here's a small grammar in neotoma's PEG format (untested):

coord_list  <- pair ("," pair)* `[ hd(Node) | [P || [",", P]  <- tl(Node)] ]`;
pair  <- "(" number "," number ")" `{lists:nth(2,Node), lists:nth(4,Node)}`;
number  <- [0-9]+ `list_to_integer(Node)`;

Sean

On Sun, Jun 20, 2010 at 1:50 PM, Rapsey  <rapsey@REDACTED > wrote:
> The best representation depends on what operations you need to perform. List
> of tuples or just a plain list of integers would most likely be best.
> Parsing that format is pretty easy:
>
> L = string:tokens("(a,b),(c,d),(e,f)","(),").
> [list_to_integer(C) || C  <- L].
>
>
> Sergej
>
> On Sun, Jun 20, 2010 at 7:43 PM, info  <info@REDACTED > wrote:
>
> > After a few manipulation with list, string, I broke my head with this
> > problem.
> >
> > I extract from a mysql database a list representing a list of coordinates.
> > The string is like this "(a,b),(c,d),(e,f) ......."
> > I would like to transform this string in order to easily manipulate each
> > coordinate.
> > What is the best representation in erlang ?
> > - a list of tupples : if yes how to transform it in [{a,b},{c,d},{e,f},
> > ....]
> > - other representations ?
> >
> > John
> >
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED


More information about the erlang-questions mailing list