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/.