------art_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   ile.basename(ARGV.to_s, ".*") + ".tif"
info     tiffinfo #{tifffile}`
width     nfo.match(/Image Width: ([0-9]{1,5})/)[1]
depth     nfo.match(/Image Length: ([0-9]{1,5})/)[1]
res     nfo.match(/Resolution: [0-9]{1,5}, ([0-9]{1,5}) pixels\/inch/)[1]

newwidth         idth.to_f / 600 * 6
newdepth         epth.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 <pbailey / bna.com> 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   ile.basename(ARGV.to_s, ".*") + ".tif"
> info     tiffinfo #{tifffile}`
> width     nfo.scan(/Image Width: ([0-9]{1,5})/)
> depth     nfo.scan(/Image Length: ([0-9]{1,5})/)
> res     nfo.scan(/Resolution: [0-9]{1,5}, ([0-9]{1,5}) pixels\/inch/)
>
> newwidth         idth.to_f / 600 * 6
> newdepth         epth.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/.
>
>

------art_25988_32451347.1199729921653--