From: Damien WYART Date: 2001-10-09T04:42:32+09:00 Subject: [ruby-talk:22257] [Newbie] Switching from Perl : suffling Dear All, Slowly switching from Perl to Ruby, I do not feel very confident with what I write in Ruby. I would like to get a script to shuffle records from STDIN to STDOUT. The Perl version I use is as follows : ,---- | #!/usr/bin/perl | | undef $/; | $/ = "\n%\n"; | | sub shuffle { | srand; | my $array = shift; | for (my $i = @$array; --$i > 0; ) { | my $j = int rand ($i+1); | @$array[$i,$j] = @$array[$j,$i]; | } | } | | while (<>) { | push (@lines, $_); | } | shuffle(\@lines); | foreach (@lines) { | print $_; | } `---- Could someone suggest a concise and nice Ruby version of this ? I think there is no Shuffle method in the Array class (I searched in Google archives). This would really be kind and would help me to get good habits. Thanks in advance, -- Damien WYART