From: mike@... (Mike Stok) Date: 2002-02-22T03:58:56+09:00 Subject: Re: Perl IO to Ruby IO help needed In article <3c752a18_2@spamkiller.newsgroups.com>, Sean Russell wrote: > > > Craig Files wrote: > >> open (DEF, "<$input_def") || die "$0: cannot read $input_def\n"; >> $/ = undef; # read the entire file... >> $_ = ; # ...into memory >> close(DEF); > > Tobias and Mike both gave you nice examples with exception handling; in the > most simple, direct from perl translation: > > lines = IO.readlines(input_def) > > This does everything you do in your perl code; it dies (with an exception) > if there is an error, and (AFAIK) the stream is automatically closed after > reading. It's also only one line long, and much easier to understand :-) But it returns an array of \n terminated strings in lines rather than the whole content of whatever's named in input_def as a single string. (It refers to the IO.readlines example above). Whether that is an important difference to the original poster I don't know, but to steal your clarity... content = File.open(input_def).read might be closer? Mike P.S. in perl it might be kinder & gentler to localise the modification to $/ if the program were bigger tahn a few lines... -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@starnix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.starnix.com/ | 75D2 9EC4 C1C0 0599 13DA