# Reading several data entries per line from screen

**URL:** <https://www.ruby-forum.com/t/reading-several-data-entries-per-line-from-screen/84269>\
**Category:** Ruby\
**Created:** [February 2, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/reading-several-data-entries-per-line-from-screen/84269 "2007-02-02T20:38:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [February 2, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/reading-several-data-entries-per-line-from-screen/84269/1 "2007-02-02T20:38:40Z")

</div>

Is there a single, easy method in Ruby that will let me read multiple  
numbers from the screen directly into multiple variables?

For instance, say I have two variable called “age” and “weight”, and  
query the user to enter them on the same line. In FORTRAN I’d just say

READ(_,_) age, weight

and when the user enters “20, 200” they are put to age and weight, as  
real variables. Can I do a similar thing in Ruby?

I did create a method that will parse the string read by “gets” into  
elements of an array, but there must be a simpler way to do this that I  
am missing.

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [February 2, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/reading-several-data-entries-per-line-from-screen/84269/2 "2007-02-02T21:38:21Z")

</div>

On 2/3/07, Alex DeCaria [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a single, easy method in Ruby that will let me read multiple  
> numbers from the screen directly into multiple variables?
> 
> For instance, say I have two variable called “age” and “weight”, and  
> query the user to enter them on the same line. In FORTRAN I’d just say
> 
> READ(_,_) age, weight

Is this what you are looking for?

name, age, weight = gets.split(/,/)  
puts name  
puts age  
puts weight

Harry

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [February 2, 2007, 9:44pm UTC](https://www.ruby-forum.com/t/reading-several-data-entries-per-line-from-screen/84269/3 "2007-02-02T21:44:14Z")

</div>

> Is this what you are looking for?
> 
> name, age, weight = gets.split(/,/)  
> puts name  
> puts age  
> puts weight
> 
> Harry

Yes, Thank You!
