Multiline gets?

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 ?

···

--
« L'ennemi, c'est comme le sexe.
  Faut tirer dessus de temps en temps pour avoir la paix. »
  (Pierre Desproges)

Hi

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 ?

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 Une Bévue <unbewusst.sein@google.com.invalid>:

--
Luis Parravicini
http://ktulu.com.ar/blog/

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

···

2010/5/10 Luis Parravicini <lparravi@gmail.com>:

Hi

2010/5/10 Une Bévue <unbewusst.sein@google.com.invalid>:

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 ?

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"

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/