Hi,

I have all of six hours of programming  experience, so I hope that
you°«ll bear with me.  Ain't all that comfortable with terminology and
such.

I opened a binary file called °»16bytes°… and read it into a string.  Then
I unpacked the string into an array of Short Integers.  At least that°«s
what I assume that I did.

What I°«d like to do is add an outside variable via the keyboard to each
element in the array.

Okay, I°«ll admit that I barely understood what I°«ve written so far, but
I think it°«s correct.  Burst my bubble, if you like.  It won°«t hurt my
feelings too much.

Here°«s the code:

whole_file = open('16bytes', 'rb') { |f| f.read}
ar1 = whole _file.unpack('S*')

puts('Enter an increase value')
incVal=gets.chomp
incVal.to_i

ar2 = ar1.collect  { |x| x + incVal}
puts ar2

I assume the thing doesn°«t work because incVal is outside of the curly
brace doo-dad.  It wouldn°«t surprise me if there°«s other problems, too.

Go nuts with the constructive criticism.

So how can  a person add a user-entered number to each value in an array
like this?

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