Not Allowing Input

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]

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"           => "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]


-----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! :stuck_out_tongue:

</syntax anal-retentiveness>


Phillip G.
Twitter: 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

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

Thanks a bunch :slight_smile: 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?