| Author |
Message |
< Erlang ~ Writing to text file |
| ishmael |
Posted: Mon Aug 25, 2008 9:59 am |
|
|
|
Joined: 23 Jul 2008
Posts: 9
Location: RSA
|
Hi,
I have been trying to write data to text file, but with no luck. I have data a list of record that I want to write to text file(comma separated style).
I have tried using file:open(S, "~w~n", write). can you help?Code: {person, {name, surname, age, interests}}.
{person, {john, dow, 23,[soccer, polo]}}.
{person, {dan, Calr, 43,[music, games]}}.
{person, {saun, Ben, 21,[soccer, rugby]}}.
Code: I want the output file to look like.
[color=red]john, dow, 23, soccer, polo[/color] all data in lines [/code] |
|
|
| Back to top |
|
| michal |
Posted: Wed Aug 27, 2008 10:17 am |
|
|
|
User
Joined: 20 Jul 2006
Posts: 44
Location: London
|
Hi,
What does it mean "no luck"? Did you get a crash? I would guess that you get undef crash, because there is no file:open function that would accept 3 arguments. Read here http://www.erlang.org/doc/man/file.html#open-2 and you will see that file:open function can only accept 2 arguments.
To write some data to a file you will need to format it. io:format/3 could be used for this (http://www.erlang.org/doc/man/io.html#format-3)
Code:
R1 = #person{name=john, surname=dow, age=23, interests=[soccer, polo]},
{ok, FileDescriptor} = file:open("output.txt", [write]),
io:format(FileDescriptor, "[color=red]~w, ~w, ~w, ~w[/color]~n",
[R1#person.name, R1#person.surname, R1#person.age, R1#person.interests]),
file:close(FileDescriptor).
Michal |
_________________ http://www.erlang-consulting.com |
|
| Back to top |
|
| rkewlani |
Posted: Mon Sep 22, 2008 6:24 am |
|
|
|
User
Joined: 10 Sep 2008
Posts: 11
|
hi,
If you want to write some data to a file, say to "a.txt"
then you can follow this approach-
1.open the file in append mode
{ok, WriteDescr} = file:open(a.txt, [raw, append]),
2.write the data on file
file:write(WriteDescr,"data to be written"),
3.close the file
file:close(WriteDescr). |
|
|
| Back to top |
|
| timrila |
Posted: Tue Jun 12, 2012 8:45 am |
|
|
|
User
Joined: 28 Mar 2012
Posts: 32
|
|
| Back to top |
|
| goods |
Posted: Fri Jun 29, 2012 2:06 am |
|
|
|
User
Joined: 28 Jun 2012
Posts: 14
|
| Christian Louboutin Homme Espadrilles est absolument représentatif de la mode et les loisirs, christian Chaussures Louboutin, est devenu une question de cours le protagoniste populaire de la saison. Nous ferons de notre mieux pour vous satisfaire. Toutes les Louboutin Pas Cher a été travaillé par des artisans et des espadrilles bonne Christian Louboutin pour les Christian Louboutin Homme par la main et c'est le résultat d'une sélection rigoureuse. si vous êtes engagé dans la vogue ou si vous voulez garder le même rythme avec la tendance, Louboutin 2012 chaussures de sport des hommes pourrait être votre meilleur choix. Commandez-le maintenant produits sont expédition libre. |
|
|
| Back to top |
|
| dongdongwu |
Posted: Thu Sep 20, 2012 5:41 am |
|
|
|
User
Joined: 19 Sep 2012
Posts: 236
|
His good friend Diane said: "Christian Louboutin Men Shoes was a magician, he make shoes is immediately put his female people with legs and advantage. He understands women wanted to do and can make them into beautiful Cinderella." Madonna often in its concert wearing Christian louboutin high heels , and some famous superstar like Angelina jolie, mariah Carey, beyonce Knowles, the famous Japanese singer YaYouMei Hamasaki helps Christian Louboutin Men Shoes set up its powerful position. The youngest customers will count Tom cruise's daughter sully cruz. Louboutin made for only a pair of handmade Christian Louboutin high heel Shoes! Want to be more fashion? Put on Christian Louboutin Outlet !
Candy colors of the chalaza high-heeled shoes with lolita type allure, set full finely gem blue "neon shoes" is to need to use "sexy" to describe. Each pair are worth careful appreciation of lithe and graceful fairy ludaoli, what kind of most let you move?Christian Louboutin Men Shoes that one brush red is always cannot resist the temptation, Christian Louboutin men outlet continue to use the days of high 8cm above slender heel proclaim the sexy and luxuriant. The bowknot on black pointed high-heeled shoes with sharp rivet concomitant, wild python met enchanting color printing grain, It is that pairs of high-heeled shoes lets Carrie more feminine flavour. Like Christian Louboutin for men her word. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
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 cannot attach files in this forum You cannot download files in this forum
|
|
|