From: Daniel Finnie Date: 2008-01-08T03:20:43+09:00 Subject: Re: Where do I put the ".to_f" ? ------=_Part_25988_32451347.1199729921653 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Scan is generally used when you have multiple matches, for example "abcdefg".scan(/../) => ["ab", "cd", "ef"]. I think in your case match is better: Dir.chdir("K:") tifffile = File.basename(ARGV.to_s, ".*") + ".tif" info = `tiffinfo #{tifffile}` width = info.match(/Image Width: ([0-9]{1,5})/)[1] depth = info.match(/Image Length: ([0-9]{1,5})/)[1] res = info.match(/Resolution: [0-9]{1,5}, ([0-9]{1,5}) pixels\/inch/)[1] newwidth = width.to_f / 600 * 6 newdepth = depth.to_f / 600 * 6 And now your code should work as intended. The [1] at the end of the match is because match returns an object that can act like an Array of [the whole match, the first parenthesis, the second parenthesis, etc...]. The reason you were getting an error before is that you were calling to_f on an Array. [4].to_f might be interpreted by a human as 4.to_f but not to Ruby. And what would ruby do if it was [2, 3, 4].to_f ? Dan On 1/7/08, Peter Bailey wrote: > > Hello, > I need to do some simply computations on numbers pulled from a file. I > get the numbers using "scan." I've proven that I can get the numbers > alright. But, I need to do some division and multiplication on those > numbers, and, to be accurate, the numbers need to be floating numbers, > not integers. So, I've tried everything, or so I think, and Ruby keeps > complaining about my ".to_f" method. Can someone please tell me where > this .to_f should go? > Thanks, > Peter > > Dir.chdir("K:") > tifffile = File.basename(ARGV.to_s, ".*") + ".tif" > info = `tiffinfo #{tifffile}` > width = info.scan(/Image Width: ([0-9]{1,5})/) > depth = info.scan(/Image Length: ([0-9]{1,5})/) > res = info.scan(/Resolution: [0-9]{1,5}, ([0-9]{1,5}) pixels\/inch/) > > newwidth = width.to_f / 600 * 6 > newdepth = depth.to_f / 600 * 6 > > I get this from Ruby: > sizer.rb:10: undefined method `to_f' for [["5100"]]:Array > (NoMethodError) > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_25988_32451347.1199729921653--