From: Holden Glova Date: 2002-11-17T16:32:20+09:00 Subject: Re: Read a file... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, 17 Nov 2002 20:13, Ted wrote: > Thanks so much for the solution. It worked, first time. > > But... as a procedural guy trying to "get" this here new-fangled OO stuff: > File.open: why no close (but only when there's a good open)? > Where's the error processing? > > I wound up trying an explicit open with begin, rescue, end; then trying to > read the file in one fell swoop (is that right?), and closing it; then > issuing the SQL statement (with its own begin, rescue, end)... > > I'm sure there's a shorter, necessary-and-sufficient way. Hi Ted, Michaels example does take care of closing the file. Here is an what File.open with a block does. [synack@Evergreen] ocelot $ ri File.open - ------------------------------------------------------------- File::open File.open( fileName, aModeString="r" ) -> file File.open( fileName [, aModeNum [aPermNum]] ) -> file File.open( fileName, aModeString="r" ) {| file | block } -> nil File.open( fileName [, aModeNum [aPermNum]] ) {| file | block } -> nil - ------------------------------------------------------------------------ With no associated block, open is a synonym for File::new. If the optional code block is given, it will be passed file as an argument, and the file will automatically be closed when the block terminates. In this instance, File::open returns nil. I strongly recommend getting the 'ri' tool. I use it all the time (http://www.ruby-lang.org/en/raa-list.rhtml?id=640). Hope this helps you. - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE910Ze0X8w8X71zPcRAlRKAJ4poRqt396IOSYGi4z2lS9Nhd012gCffI/x 40Tgt4v5W8AJZI7OTjltW28= =DvRA -----END PGP SIGNATURE-----