From: William James Date: 2006-02-03T04:43:17+09:00 Subject: Re: Chomping and stomping ara.t.howard@noaa.gov wrote: > On Fri, 3 Feb 2006, William James wrote: > > > > > John Maclean wrote: > >> Chaps, > >> > >> Here's a short script to keep requesting for input... > >> > >> #!/usr/bin/ruby -w > >> def chomper > >> xx = gets.chomp! > >> until $_ == "qq" > >> puts "hit me with a squirell!" > >> xx = gets.chomp! > >> xx > >> end > >> end > >> > >> chomper > >> > >> # this works but surely there must be a way to incoporate a variable > >> in there? > >> > >> #!/usr/bin/ruby -w > >> def chomper > >> xx = gets.chomp! > >> until xx == "qq" > >> puts "hit me with a squirell!" > >> xx > >> end > >> end > >> > >> #this don't work. > > > > > > def chomper > > until (xx = gets.chomp) == 'qq' > > puts "hit me with a squirell!" > > end > > xx > > end > > > > puts chomper > > > harp:~ > cat a.rb > def chomper > until (xx = gets.chomp) == 'qq' > puts "hit me with a squirell!" > end > xx > end > > puts chomper > > > harp:~ > ruby a.rb < /dev/null > a.rb:3:in `chomper': private method `chomp' called for nil:NilClass (NoMethodError) > from a.rb:9 The error I get in a dos-box is The system cannot find the path specified. To produce the error you gave, I must do it this way: ruby a.rb < nul: When you post something that depends upon a particular operating system, you need to make that dependency clear. It is reasonable to write a program that requires input. It is not reasonable to expect a program that requires input to function properly when you deliberately deprive it of input.