This is a multi-part message in MIME format.
------ extPart_000_000B_01C16401.B84A3360
Content-Type: text/plain;
charset so-8859-1"
Content-Transfer-Encoding: quoted-printable
I installed winruby a while back. I've been using ruby from the command line like so: ruby my_prog.rb and so far it's worked great, but I came across something I can't figure out. I tried this code:
if fileName != nil then
IO.readlines(fileName).each{|line|
line.chomp!
$lines << line
}#end IO.readlines...each
end #if fileName
while command = gets
print command
end #while
Ideally it should read the contents of a file whose name I specify on the command line and then prompt the user for input and print that input. but the calls to gets are going to the file object opened by IO.readlines. I can fix this with an explicit $stdin.get, but that's kind of a hack. I can also throw in this code:
while trash = gets
end
and it consumes the file object from IO.readlines and lets me get on with reading from standard input. But again that's a hack. Is there some way to force gets() back to reading from standard input. i.e. to properly close out the file. I thought Using File.new and then explictly closing the object it returns would do that, but this code:
if fileName != nil then
inputFile = open fileName
begin
inputFile.each {|line|
line.chomp!
$lines << lline
}#end inputFile.each
ensure
inputFile.close
end #end begin..ensure
end #if
has the same problem. Can someone tell me what's going on here. I'm totally lost. Thanks again
Jeremy Gregorio
rsilvergun / home.net
------ extPart_000_000B_01C16401.B84A3360
Content-Type: text/html;
charset so-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2> I installed winruby a while
back. I've been using ruby from the command line like so: ruby my_prog.rb and so
far it's worked great, but I came across something I can't figure out. I tried
this code:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>if fileName != nil
then<BR> <BR> IO.readlines(fileName).each{|line|<BR> <BR> line.chomp!<BR> $lines
<< line<BR> <BR> }#end
IO.readlines...each<BR> <BR>end #if fileName<BR>
<BR>while command = gets<BR></FONT></DIV>
<DIV><FONT face=Arial size=2> print command</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>end #while</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Ideally it should read the contents of a file whose
name I specify on the command line and then prompt the user for input and print
that input. but the calls to gets are going to the file object opened by O.readlines. I can fix this with an explicit $stdin.get, but that's kind of a
hack. I can also throw in this code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>while trash = gets<BR>end</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>and it consumes the file object from IO.readlines
and lets me get on with reading from standard input. But again that's a hack. Is
there some way to force gets() back to reading from standard input. i.e. to
properly close out the file. I thought Using File.new and then explictly closing
the object it returns would do that, but this code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>if fileName != nil then</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> inputFile = open
fileName<BR> <BR> begin<BR> inputFile.each {|line|
<BR> <BR> line.chomp!<BR> $lines
<< lline<BR> }#end
inputFile.each<BR> <BR> ensure<BR> <BR> inputFile.close</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> end #end begin..ensure</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>end #if<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>has the same problem. Can someone tell me what's
going on here. I'm totally lost. Thanks again</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Jeremy Gregorio</FONT></DIV>
<DIV><FONT face=Arial size=2><A
href="mailto:rsilvergun / home.net">rsilvergun / home.net</A></FONT></DIV>
<DIV><FONT face=Arial size=2> </DIV></FONT></BODY></HTML>
------ extPart_000_000B_01C16401.B84A3360--