On Fri Jun 16, 2006 at 10:39:36 +1000, Matthew Palmer wrote:
>On Fri, Jun 16, 2006 at 09:58:34AM +1000, O Plameras wrote:
>> #!/usr/bin/env ruby
>> puts $stdin.readlines.sort_by {rand} unless $stdin.eof
>
>The whole EOF bit is unnecessary, although the puts-on-the-same-line is a
>good cleanup.
>

Hi Matt, 

Got a question. Is:

puts $stdin.readlines.sort_by {rand} 

better than:

a = $stdin.readlines.sort_by {rand} 
puts $stdin

For any reasons other than stylistic? (And more importantly, why? I
can imagine depending on how the language is implemented that it could
result in serious performance difference on large files.)

Oh and my other question, which was partly answered elsewhere was what
does readlines return? I think I read elsewehere in the thread that it 
was an array, but somewhere else mentioned it was an iterator?

Also, what exactly does puts do? In a kinda of direct translation to python
(well ignoring the sorting bit ;):

print sys.stdin.readlines()

Would result in printing an actual array. E.g:

["foo\n", "bar\n", baz\n"]

I assume that puts just does:

foo
bar
baz


I'd just like to know why exactly.

Cheers,

Benno

(If this gets too tedious just tell me to RTFM ;)
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to