From: Ignatz Hafflegab Date: 2007-08-25T08:03:54+09:00 Subject: Re: add outside variable to array elements Thank you, Alex Gutteridge. incVal = incVal.to_i worked just as you suspected it would. And thank you, botp, for the irb suggestion. My apologies for the typos, as well as for not supplying error messages. The computer I was using at the time didn't have Ruby, so I had to rely on my faulty memory. The vodka probably didn't help matters much. I've done some more reading, and I'm a little embarrassed at having called a code block a "curly brace doo-dad." BTW, I couldn’t find anything about cut&paste in the Core API documentation. I have this code now: whole_file = open('16bytes', 'rb') { |f| f.read} ar1 = whole_file.unpack('S*') puts('Enter an increase value') incVal=gets.chomp incVal = incVal.to_i ar2 = ar1.collect { |x| x + incVal} ar2= ar2.pack('S*') open('output','wb'){|f| f.write ar2} But there's a problem with this. If, for instance, '16bytes' contained the Short 65535 and incVal=12, the result would be 65547. That's too big to store as a Short. The 65547 wraps over to 11 when it gets saved in 'output'. Is there any way to iterate over an array and apply a conditional like if x < 45000 then x = x + incVal rather than having everything in the array get incVal added to it? I doubt that I’ll ever have an incVal over 20000. PS I was joking about cut&paste. -- Posted via http://www.ruby-forum.com/.