O Plameras wrote:
Graham Smith wrote:
#!/usr/bin/ruby
a=STDIN.readlines.sort_by {rand}
puts a
I'm new to Ruby. I understand Ruby was developed
to make the codes easy to read by Programmers (Humans)
more than to make it abiding by the machine logic.
This is not to say that the foregoing code is faulty
but to show an alternative way.
So, this is how I'd code it.
#!/usr/bin/env ruby
puts $stdin.readlines.sort_by {rand} unless $stdin.eof
In human terms, it says 'put the lines that I got from standard input
by sorting these lines randomly unless it is(excluding) the end-of-file'.
O Plameras
Don't know ruby at all, so I'd like to understand the need for the
"unless $stdin.eof" part.
"unless" means "exclude"
"$stdin.eof" means "standard-input is end-of-line".
So, it means "exclude when standard-input is end-of-line" as
stated in last sentence of previous post. Tutorials I've been
through use this.
Matt has pointed out this is now redundant but no harm
saying. No errors/warnings are generated by my Ruby interpreter.
O Plameras
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders