--0016e640985acc829a046359d89b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Feb 19, 2009 at 7:03 PM, Igor Pirnovar <gooigpi / gmail.com> wrote: > If you are planning to do some data entry checking on Linux platforms > you may need to set the STDOUT.sync rue. I am including a simple > program to show you the difference. Indeed on MS Windows you will not > experience any difference if you comment out "STDOUT.sync rue"; on > Linux if buffering is turned on you will! > > > STDOUT.sync rue > > #!/usr/bin/env ruby > > STDOUT.sync rue # (cross-platform compatibility issue) > > loop do > print "\n\n\tPLEASE SELECT:\n\n" > print "\t\t(1) ..... enter one number\n" > print "\t\t(2) ..... enter two numbers " > print "(no seoarators like commas, ...)\n" > print "\t\t(Q) ..... Quit\n\n" > print "\tPlease select one of the above: " > answer ets > printf "You've selected %s\n", answer > > case answer.chomp > when "1" > num il > while num !~ /\d+.*[^\d]*/ > print "Please enter a single number: " > num ets > num.chomp! # note exclamation mark (!) > if num.split(/\s+/).size ! || num !~ /\d+/ > puts "You should have entered a single number not [#{num}]" > print "Press <Enter> to continue " > any ets > else > puts "Thank you for [#{num}]." > end > end > when "2" > num il > while num !~ /\d+[\s,]+\d+/ > print "Please enter two numbers: " > num ets > num.chomp! # note exclamation mark (!) > if num.split(/\s+/).size ! || num !~ /\d+\s+\d+/ > puts "You must enter two numbers number, not [#{num}]" > print "Press <Enter> to continue " > any ets > else > puts "Thank you for [#{num}]." > end > end > when /q|Q/ > exit > else > print "Illegal selection; Please try again! " > print "Please enter a single number:\n" > print "Press <Enter> to continue " > any ets > end > end > > -- > Posted via http://www.ruby-forum.com/. > > I truly appreciate the abundance of suggestions from everyone. I will try every suggestion and pick one! Thank you -- Ruby Student --0016e640985acc829a046359d89b--