From: dblack@... Date: 2002-10-22T06:33:11+09:00 Subject: Re: functional Ruby equiv to this perl snippet Hi -- On Tue, 22 Oct 2002, Mirian Crzig Lennox wrote: > On Tue, 22 Oct 2002 05:54:49 +0900, Bob X wrote: > > > >Cool..but what if serverlist.txt does not exist? The one thing I do like > >about Perl is the "open file or die" test. I believe that I am "stuck" with > >a rescue clause which is sometimes confusing for me (a newbie) to use when > >it is located within a "def". > > You can do something very similar in Ruby, using "fail" instead of "die". > For example: > > def open_file name > f = File.open(name) or fail "couldn't open #{name}" > return f > end If an exception is raised by the open, though, the fail clause will not be executed: $ ruby -e 'File.open("NO_FILE") or fail "Not reached"' -e:1:in `open': No such file or directory - "NO_FILE" (Errno::ENOENT) from -e:1 David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav