# Not Allowing Input

**URL:** <https://www.ruby-forum.com/t/not-allowing-input/136065>\
**Category:** Ruby\
**Created:** [April 28, 2008, 4:03pm UTC](https://www.ruby-forum.com/t/not-allowing-input/136065 "2008-04-28T16:03:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aslambilal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aslambilal](https://www.ruby-forum.com/u/aslambilal)\
**Post date:** [April 28, 2008, 4:03pm UTC](https://www.ruby-forum.com/t/not-allowing-input/136065/1 "2008-04-28T16:03:55Z")

</div>

Well i’m trying to make a program for newbie practice and, in the while  
loop at the bottom, i am not allowed to put in any information when i  
run it. Can anyone help me out? Thanks

[src]  
#!/usr/bin/ruby

sim\_outorder\_path = “/home/software/simplescalar/bin/sim-outorder”

puts “Welcome to the sim-outorder configuration utility.”

# Put output name into script\_name and remove the ‘\n’

puts “Enter script output name.”  
script\_name = gets  
script\_name.chomp

# simplesim holds the names of and default values of the parameters

default\_options =  
{

```
"fastfwd" => "300000",
"max:inst" => "2000000",

```

# “config” =\> nil,

# “dumpconfig” =\> nil,

# “h” =\> “true”,

# “v” =\> “false”,

# “d” =\> “false”,

# “i” =\> “false”,

# “seed” =\> “1”,

# “q” =\> “false”,

# “chkpt” =\> nil,

```
"fetch:ifqsize" => "4",
"fetch:mplat" => "3",
"fetch:speed" => "1",

```

# “bpred” =\> “bimod”,

# “bpred:bimod” =\> “2048”,

# “bpred:2lev” =\> “1 1024 8 0”,

# “bpred:comb” =\> “1024”,

# “bpred:ras” =\> “8”,

```
"bpred:btb" => "512 4",

```

# “bpred:spec\_update” =\> nil,

```
"lsq:size" => "8",

"cache:dl1" => "dl1:128:32:4:l",
"cache:dl1lat" => "1",
"cache:dl2" => "ul2:1024:64:4:l",
"cache:dl2lat" => "6",
"cache:il1" => "il1:512:32:1:l",
"cache:il1lat" => "1",
"cache:il2" => "dl2",
"cache:il2lat" => "6",

```

# “cache:flush” =\> “false”,

# “cache:icompress” =\> “false”,

```
"mem:lat" => "18 2",
"mem:width" => "8",

```

# “tlb:itlb” =\> “itlb:16:4096:4:l”,

# “tlb:dtlb” =\> “dtlb:32:4096:4:l”,

```
"tlb:lat" => "30",

"res:ialu" => "4",
"res:imult" => "1",
"res:memport" => "2",
"res:fpalu" => "4",
"res:fpmult" => "1"

```

}

# Initialize user\_options

user\_options = “”

# Print the defaults and ask for changes

default\_options.each\_key do |key|

# Show the option\_name and the default value

puts key.to\_s + "\tDefault = " + default\_options[key].to\_s  
puts “Type ‘d’ to use default value”

# Get the option\_value or d

# Set to " " to allow while loop to work

option\_value = " "

# While user input is nothing

while option\_value == “”  
option\_value = gets.chomp.to\_s  
end

if option\_value.to\_s == “d”  
# Use default value  
user\_options += “-” + key.to\_s + " " + default\_options[key].to\_s + "  
"  
else  
# Use given value  
# user\_options += “-” + key.to\_s + " " + option\_value + " "  
end

end

[/src]

---

<div class="post-metadata">

**Author:** ![aslambilal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aslambilal](https://www.ruby-forum.com/u/aslambilal)\
**Post date:** [April 28, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/not-allowing-input/136065/2 "2008-04-28T16:25:41Z")

</div>

Not sure exactly what you're asking but I see two issues:

```
_script\_name = gets script\_name.chomp_
```
should be  

```
_script\_name = gets.chomp_
```
and  

```
_# Set to " " to allow while loop to work option\_value = " "
# While user input is nothing_
 

while option\_value == “”  
option\_value = gets.chomp.to\_s  
end
```
  
will never execute the while loop since option\_value is set to a  
non-empty string.  
  
  
  
  
  
Bilal Aslam wrote:

> ```
> Well i'm trying to make a program for newbie practice 
> and, in the while
> loop at the bottom, i am not allowed to put in any information when i
> run it. Can anyone help me out? Thanks
> 
> [src]  
> #!/usr/bin/ruby
> 
> sim\_outorder\_path = “/home/software/simplescalar/bin/sim-outorder”
> 
> puts “Welcome to the sim-outorder configuration utility.”
> 
> # Put output name into script\_name and remove the ‘\n’
> 
> puts “Enter script output name.”  
> script\_name = gets  
> script\_name.chomp
> 
> # simplesim holds the names of and default values of the parameters
> 
> default\_options =  
> {
> 
> ```
> "fastfwd" =&gt; "300000",
> "max:inst" =&gt; "2000000",
> 
> ```
> 
> # “config” =\> nil,
> 
> # “dumpconfig” =\> nil,
> 
> # “h” =\> “true”,
> 
> # “v” =\> “false”,
> 
> # “d” =\> “false”,
> 
> # “i” =\> “false”,
> 
> # “seed” =\> “1”,
> 
> # “q” =\> “false”,
> 
> # “chkpt” =\> nil,
> 
> ```
> "fetch:ifqsize" =&gt; "4",
> "fetch:mplat" =&gt; "3",
> "fetch:speed" =&gt; "1",
> 
> ```
> 
> # “bpred” =\> “bimod”,
> 
> # “bpred:bimod” =\> “2048”,
> 
> # “bpred:2lev” =\> “1 1024 8 0”,
> 
> # “bpred:comb” =\> “1024”,
> 
> # “bpred:ras” =\> “8”,
> 
> ```
> "bpred:btb" =&gt; "512 4",
> 
> ```
> 
> # “bpred:spec\_update” =\> nil,
> 
> ```
> "lsq:size" =&gt; "8",
> 
> "cache:dl1" =&gt; "dl1:128:32:4:l",
> "cache:dl1lat" =&gt; "1",
> "cache:dl2" =&gt; "ul2:1024:64:4:l",
> "cache:dl2lat" =&gt; "6",
> "cache:il1" =&gt; "il1:512:32:1:l",
> "cache:il1lat" =&gt; "1",
> "cache:il2" =&gt; "dl2",
> "cache:il2lat" =&gt; "6",
> 
> ```
> 
> # “cache:flush” =\> “false”,
> 
> # “cache:icompress” =\> “false”,
> 
> ```
> "mem:lat" =&gt; "18 2",
> "mem:width" =&gt; "8",
> 
> ```
> 
> # “tlb:itlb” =\> “itlb:16:4096:4:l”,
> 
> # “tlb:dtlb” =\> “dtlb:32:4096:4:l”,
> 
> ```
> "tlb:lat" =&gt; "30",
> 
> "res:ialu" =&gt; "4",
> "res:imult" =&gt; "1",
> "res:memport" =&gt; "2",
> "res:fpalu" =&gt; "4",
> "res:fpmult" =&gt; "1"
> 
> ```
> 
> }
> 
> # Initialize user\_options
> 
> user\_options = “”
> 
> # Print the defaults and ask for changes
> 
> default\_options.each\_key do |key|
> 
> # Show the option\_name and the default value
> 
> puts key.to\_s + "\tDefault = " + default\_options[key].to\_s  
> puts “Type ‘d’ to use default value”
> 
> # Get the option\_value or d
> 
> # Set to " " to allow while loop to work
> 
> option\_value = " "
> 
> # While user input is nothing
> 
> while option\_value == “”  
> option\_value = gets.chomp.to\_s  
> end
> 
> if option\_value.to\_s == “d”  
> # Use default value  
> user\_options += “-” + key.to\_s + " " + default\_options[key].to\_s + "  
> "  
> else  
> # Use given value  
> # user\_options += “-” + key.to\_s + " " + option\_value + " "  
> end
> 
> end
> 
> [/src]
> ```

---

<div class="post-metadata">

**Author:** ![aslambilal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aslambilal](https://www.ruby-forum.com/u/aslambilal)\
**Post date:** [April 28, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/not-allowing-input/136065/3 "2008-04-28T20:30:07Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Praveen R. wrote:  
| Not sure exactly what you’re asking but I see two issues:  
|  
| /script\_name = gets  
| script\_name.chomp/  
|  
| should be  
|  
| /script\_name = gets.chomp/

Or it _could_ be script\_name = script\_name.chomp, since #chomp is  
non-destructive.

So, if should be anything, it should be script\_name.chomp! 😛

\</syntax anal-retentiveness\>

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

~ - You know you’ve been hacking too long when…  
…you almost get hit by a bus that pulled away from the stop without  
looking and you say: PANIC: bus error  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkgWF3kACgkQbtAgaoJTgL9WYwCghP501XoDppZ2z8luidjiGgrj  
stoAnRFc2YmKNGDamyZRyB98hdP6wPA4  
=2nt9  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![aslambilal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aslambilal](https://www.ruby-forum.com/u/aslambilal)\
**Post date:** [April 28, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/not-allowing-input/136065/4 "2008-04-28T18:28:40Z")

</div>

Thanks a bunch 🙂 That fixed my problem :).

Just to be clear, when getting input from a while loop i should always  
do

variable = gets.chomp

instead of

variable = gets  
variable.chomp

or w/e operation im doing to the variable right?
