On Sat, Nov 12, 2011 at 21:42, Reese C. [email protected]
Ok, that does work- so the problem is with how the data is being inputted,
not with the program?
No, it’s the program, if you do indeed want to use gets. Thing is,
you’re just using gets once, and gets just reads one line. I don’t
see how you could have wound up with multi-line results from one gets
call in irb. Possibly the modifications you glossed over, were doing
a good bit more than that. Anyway, there are a couple alternate
suggestions that spring to mind.
One is to use a different input reading function that will read until
end-of-file, and then split it as you were doing. The user must press
^Z when done (^D on Mac or Linux). However, typical non-technical
end-users might not understand things like “press ^Z”. (I’m guessing
this is really just an academic exercise so that wouldn’t really
matter, but it’s still a good idea to get into the habit of thinking
about what your users will understand or not.) Also, reading until
EOF in one chunk can be a dangerous habit to get into, as some joker
(or malicious attacker) may enter much more data than your program can
really handle. (Again, good habit to get into thinking about security
A much better way is to put gets in a loop with some condition to end
it, such as entering a blank line. How to initialize the data and
execute that loop, are left as exercises for the reader.