if a use :
sml = “”
while s = STDIN.gets
sml += s
end
i get two times what’s on STDIN, why ?
may be something to flush, generally it’s stdout hum ?
if a use :
sml = “”
while s = STDIN.gets
sml += s
end
i get two times what’s on STDIN, why ?
may be something to flush, generally it’s stdout hum ?
Hi
2010/5/10 Une Bévue [email protected]:
if a use :
sml = “”
while s = STDIN.gets
sml += s
endi get two times what’s on STDIN, why ?
may be something to flush, generally it’s stdout hum ?
Are you sure? How did you check that?
irb(main):001:0> sml = “”
=> “”
irb(main):002:0> while s = STDIN.gets
irb(main):003:1> sml += s
irb(main):004:1> end
1
2
3
=> nil
irb(main):005:0> sml
=> “1\n2\n3\n”
2010/5/10 Luis P. [email protected]:
may be something to flush, generally it’s stdout hum ?
3
=> nil
irb(main):005:0> sml
=> “1\n2\n3\n”
Also, there are much easier ways to read the complete input than to use
#gets:
13:46:50 $ seq 1 3 | ruby19 -e ‘p STDIN.read’
“1\n2\n3\n”
13:46:57 $ seq 1 3 | ruby19 -e ‘STDIN.each_line {|l| p l}’
“1\n”
“2\n”
“3\n”
13:47:50 $
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs