Thanks Jim for another approach.

I saw the use of "eval" in Jim Fulton's "The Ruby Way" but didn't quite 
understand it.  I do plan to filter the data to make sure that the 
numbers are there and the format is consistent.

The input data format is a natural and easy way to specify the problem 
I'm trying to solve, so I'll keep the format but do the evaluation 
inside the code.

Thanks again.

Pete Versteegen


Jim Lindley wrote:
> If your data really is in that format, you can add an extra set of
> brackets around the whole thing to read it in as an array literal.
> Just be sure that the data source is trustworthy and you if you're
> going to eval it! If you aren't generating or strongly filtering the
> inputs this is probably a bad idea.
> 
> irb> input = "[25.0, 26], [30, 31]"
> => "[25.0, 26], [30, 31]"
> irb> input = "[" + input + "]"
> => "[[25.0, 26], [30, 31]]"
> irb> eval input
> => [[25.0, 26], [30, 31]]
> irb> result = eval input
> => [[25.0, 26], [30, 31]]
> irb> result[0][1]
> => 26
> 
> But maybe you were just simplifying the input data format to present
> the problem?


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