From: Thomas Luedeke Date: 2008-07-31T04:33:29+09:00 Subject: Re: Loop behavior not understood (newbie) Gregory Brown wrote: > On Wed, Jul 30, 2008 at 2:59 PM, Thomas Luedeke > wrote: > >> When running Ruby 1.8.7 on Eclipse, this results in nothing being >> printed to the detailed_model_mod file. If I take out the if-end loop >> trying to pattern match the string with the leading "41", then it prints >> out fine. > > Does this code give you what you want? > > ### > > check_disabled = false > > File.open( "detailed_model_mod", "w" ) do |mod| > File.foreach("detailed_model") do |line| > mod.puts(line) if check_disabled || line =~ /^\s*[\*]/ > check_disabled = true if line =~ /^\s*41/ > end > end > > ### > > I *think* it does the same thing as yours, but it is sure to close the > file handles cleanly. When I ran your code however, I was able to get > some output. > > If this isn't what you want, please provide a sample data set and show > what you expect the output to be. > > -greg If I change "detailedModelModified.puts line" to "puts line" in my coding, it works as intended. The problem is in the print to the detailedModelModified file. I'll try your version and see if it works in my coding. Be back in a minute. -- Posted via http://www.ruby-forum.com/.