From: Wladimir Mutel Date: 2002-04-24T21:16:52+09:00 Subject: Re: My First Time � ������ <200204240855.g3O8tRu21875@sharui.nakada.kanuma.tochigi.jp> Nobuyoshi Nakada �������(�): >> Because Ruby has a lot of qualities that are quite different from >> other languages, I would like to ask you to have a look over my >> program and tell me where I break conventions or what else could be >> done better. It's a fortune clone. >> >> - - - Schnipp - - - >> #! /usr/bin/ruby -w >> >> fileName = "/home/yooden/.mail/keywords"; >> sigDivider = '~###~' > > If you want to split the file by exact "~###~" lines, > > sigDivider = "~###~\n" > sigs = IO.readlines(fileName, sigDivider).each {|s| > s.chomp!(sigDivider) > } > print sigs[rand(sigs.size)] There is also mathematically nice recipe for picking random line from the file. In Perl at http://www.oreilly.com/catalog/cookbook/chapter/ch08.html#chap08_picking_0 and in Python at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/59865 It is ecological, by not reading entire file into the array of strings. It is easy to write the same in Ruby.