From: Dave Thomas Date: 2000-03-14T21:47:19-06:00 Subject: [ruby-talk:01825] Very strange problem in chomp and/or sub, or with me I have a very strange problem with chomp, but I can't produce a simple test case that demonstrates it. I'm going to continue trying, but in the meantime I thought I'd post what I _do_ know in the hope that someone will say "ah yes..." This is with the latest CVS. I have an array, 'result', which I populate using 'readlines'. I then pass it in to a routine which effectively does: for op in result if op =~ /^<<(\d+)>>/ lineNo = $1.to_i op.gsub!(/^<<\d+>>/, '') end comment[lineNo] = op.chomp fullEscape(comment[lineNo], sp) end Where fullEscape is: def fullEscape(line, space) $stderr.print "FE: ", line s = line.sub(/\s+$/, ''). gsub(/\\/, "\\bs\?C-q"). gsub(/([_\${}&%#])/, '\\\\\1'). gsub(/\?C-q/, "{}"). gsub(/\^/, "\\up{}"). gsub(/~/, "\\sd{}"). gsub("<<", "<{}<"). gsub(/ /, space) $stderr.print "-> ", s, "\n" s end Whn this runs in the the context of the larger program, I get the following trace: FE: [10, 15, 22, 120]-> [10,\ 15,\ 22,\ 120]^@ 18: '[0.8333333333, 1.25, 1.833333333, 10.0]' FE: [0.8333333333, 1.25, 1.833333333, 10.0]-> [0.8333333333,\ 1.25,\ 1.833333333,\ 10.0]^@ Note the NULL character added to the end of the result. However, if I change the op.chomp call in the loop to comment[lineNo] = op[0..-2] The NULL goes away. Similarly, if I change the call to fullEscape to be fullEscape(comment[lineNo]+'', sp) the NULL goes away too. The frustrating thing is that I haven't been able reproduce this in a smaller test program. Am I doing something stupid here? Dave