Rewrite data to a file

J

Joyce Lima

rewrite data to a file.

I have a file with the following data

1!name!registration!login

This means that 1 "is written on file" when
receive the login keyboard have to replace that
1 0, which would be the logical exclusion. Does anyone know
how do you rewrite data in ruby?

Thank you very much!
 
B

brabuhr

I have a file with the following data

1!name!registration!login

This means that 1 "is written on file" when
receive the login keyboard have to replace that
1 0, which would be the logical exclusion. Does anyone know
how do you rewrite data in ruby?

Are you able to write a (new) file with the correct data?

Generally, the safe way to update a file is to read from the old file,
write to a temporary file, and move the temporary file over the old
file.

* Are all of the updates you need to make of the form: 0 <-> 1
* How often do you need to update the file
* When you update the file, how many updates are made
* How large is your file (tens of lines or thousands or billions)
 
E

Emil Kampp

The syntax for opening the file would be:

File.open('/path/to/file').write{ |f| f.write('some data') }
 
P

Phillip Gawlowski

The syntax for opening the file would be:

File.open('/path/to/file').write{ |f| f.write('some data') }

Note for Windows users:

File.open "c:/path with spaces to/file.name"

and

File.open "C:\\path with spaces to\\file.name"

are equally valid (Windows accepts both forward- and backslashes in
paths these days).


--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,135
Messages
2,570,784
Members
47,342
Latest member
KelseyK737

Latest Threads

Top