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

_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to