Hal.....Possible memory bug in Ruby? I'm stumped!

Hal-

I just tried the line you recommended way below. I got this error:

t8.rb:25 undefined method ‘write’ for #Object:0x2e99610
from t8.rb:25:in 'open"
from t8.rb.25
from t8.rb:14:in ‘foreach’
from t8.rb:14

Thoughts? (My original line works ok, but I’d be interested in getting yours to work for file-close-guarantee purposes.)

THanks!

-Kurt

···

-----Original Message-----
From: Hal E. Fulton [mailto:hal9000@hypermetrics.com]
Sent: Sunday, June 09, 2002 8:20 PM
To: ruby-talk@ruby-lang.org
Subject: Re: Park and others!..Possible memory bug in Ruby? I’m
stumped!

----- Original Message -----
From: “Kurt Euler” keuler@portal.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Sunday, June 09, 2002 10:11 PM
Subject: RE: Park and others!..Possible memory bug in Ruby? I’m stumped!

File.new(“./output/”+field[0],“w+”).write(content2)

Because an error occured here in one test, it appears that this
line, like those before it, may also create an OS file. If this
is true, is there way to rewrite THIS line to force a close the
file during or just after the line executes? Or, perhaps
immediate garbage collection occurs with this
command, so I needn’t worry.

Kurt,

Not sure I understand all your constraints, since I haven’t
closely followed this thread.

But be aware that ‘open’ is essentially the same as ‘new’ except
that it can take a block. If it’s given a block, the file will
be closed after the block is executed.

File.open(“./output/#{field[0]}”, “w+”) { write(content2) }

file is now closed

Does this help any?

By the way, my change to the file name is irrelevant… I just
wanted to illustrate a potentially clearer way of doing that
append.

Hal Fulton

Try this:

File.open("./output/#{field[0]}", "w+") { |file| file.write(content2) }

– Dossy

···

On 2002.06.10, Kurt Euler keuler@portal.com wrote:

I just tried the line you recommended way below. I got this error:

t8.rb:25 undefined method ‘write’ for #Object:0x2e99610
from t8.rb:25:in 'open"
from t8.rb.25
from t8.rb:14:in ‘foreach’
from t8.rb:14

Thoughts? (My original line works ok, but I’d be interested in getting
yours to work for file-close-guarantee purposes.)


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I just tried the line you recommended way below. I got this error:

t8.rb:25 undefined method ‘write’ for #Object:0x2e99610
from t8.rb:25:in 'open"
from t8.rb.25
from t8.rb:14:in ‘foreach’
from t8.rb:14

Thoughts? (My original line works ok, but I’d be interested in getting
yours to work for file-close-guarantee purposes.)

Try this:

File.open("./output/#{field[0]}", "w+") { |file|

file.write(content2) }

– Dossy

Quite right. Thanks Dossy…

Hal Fulton

···

----- Original Message -----
From: “Dossy” dossy@panoptic.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Sunday, June 09, 2002 11:06 PM
Subject: Re: Hal…Possible memory bug in Ruby? I’m stumped!

On 2002.06.10, Kurt Euler keuler@portal.com wrote: