Re: False positives in editing data



On Nov 19, 2:42 am, Harry Kakueki <list.p...@xxxxxxxxx> wrote:
Problem solved!

I went through a convoluted process to determine whether any of the
initial numbers began with a zero. I simplified it to:

i_thNumberHasLeadingZero = (n[i] =~ /^0+/) ? true : false

I apologize for raising the question. My excuse is that I was
flailing about unable to figure out what was wrong. After I posted,
I took a harder look and realized my big mistake: I needed to use the
KISS method :-)

Best wishes,
Richard

If you solved your problem then you won't need this.
But, just in case you are interested in looking at it from a little
different view....
It is not a complete solution, just an idea.

inp = <<DATA
05Topic 5
1Topic 1
2.002.1Topic 2.2.1
2.1Topic 2.1
2.2.02Topic 2.2.2
DATA

err1 = inp.select{|a| a =~ /^0|\.0/}
puts "A number may not start with zero" unless err1.empty?
print err1
puts
err2 = inp.select{|b| b =~ /^\d+\.\d+\.\d/}
puts "No more that two numbers may be prefixed" unless err2.empty?
print err2

Harry

--
A Look into Japanese Ruby List in Englishhttp://www.kakueki.com/ruby/list.html

Hi Ryan,

But, just in case you are interested in looking at it from a little
different view....
It is not a complete solution, just an idea.

I AM interested, and it's a great idea. Real Ruby rather than my C-
flavored Ruby :-)

Just for our mutual amusement, I replaced your first criterion:

err1 = inp.select{|a| a =~ /^0|\.0/}

with:

err1 = inp.select{|a| a =~ /^0|^\d*\.0/}

to preclude false hits where the text proper might contain ".0", e.g.,
"7How to get 5.05% interest"

Bottom line: Your code is what I really need. Thanks, again.

Best wishes,
Richard

.



Relevant Pages

  • Re: False positives in editing data
    ... initial numbers began with a zero. ... I apologize for raising the question. ... puts "A number may not start with zero" unless err1.empty? ...
    (comp.lang.ruby)
  • Re: Why is this not a syntax error?
    ... |Switching back and forth between Python and Ruby bit me in the butt ... consider the following Ruby code: ... | puts 'zero' ...
    (comp.lang.ruby)
  • Ruby script to Module/Class refactor
    ... I have written my first live ruby script that actually performs useful ... # and append .csv extension to each. ... puts FileTest.readable?? ...
    (comp.lang.ruby)
  • Re: lowering rubys reach
    ... Don't get me wrong it should make it a lot easier to write extensions for ruby - especially those that are merely for speed gains. ... What I was think of was the introduction of language profiles which would trigger certain language features. ... would complain about variable a not being declared and would need to be change to include a forward declaration, ...
    (comp.lang.ruby)
  • Re: Suggestion: swap name of "puts" and "print" and rename "puts" to "put_s"
    ... character and "puts" doesn't. ... Because that's how it is in the C language: ... Either way, just make it consistent. ... One of the benefits I have found from using Ruby is that it actively ...
    (comp.lang.ruby)