Rewrite data to a file

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!

···

--
Posted via http://www.ruby-forum.com/.

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)

···

On Thu, Mar 24, 2011 at 4:29 PM, Joyce Lima <jojosl@hotmail.com> wrote:

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?

look at gsub.

···

On Thu, Mar 24, 2011 at 3:29 PM, Joyce Lima <jojosl@hotmail.com> wrote:

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!

--
Posted via http://www.ruby-forum.com/\.

The syntax for opening the file would be:

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

···

--
Posted via http://www.ruby-forum.com/.

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).

···

On Fri, Mar 25, 2011 at 1:04 AM, Emil Kampp <ekampp@gmail.com> wrote:

The syntax for opening the file would be:

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

--
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.