On Thu, 18 May 2000, Vivek Khera wrote:

> >>>>> "DM" == Doug MacEachern <[EMAIL PROTECTED]> writes:
> 
> DM> On Wed, 17 May 2000, Matt Sergeant wrote:
> >> Well, this may be true, but if you load IO::File before startup then it's
> >> not too big a deal...
> 
> DM> but it still adds a great deal of bloat to the server.  and it's oo
> DM> interface, while very slick, adds quite a bit of runtime overhead, turn
> DM> the sugar sour imo.
> 
> In an embedded environment like mod_perl, then how do you suggest to
> deal with the dangling file handles problem?  That is, I'm processing
> a file or two, and some error occurs.  In a normal perl program, I'd
> exit or return out and then when the program terminates, it
> automagically closes all the files.  In mod_perl, the auto-close
> doesn't happen until much later.  With the OO interface, when the
> handle goes out of scope, such as a function call return, the file is
> implicitly closed.
> 
> What other mechanism do you propose to handle this situation other
> than IO::File?  I use it all the time myself.

in addition to stas' hints, even local *FH does the job, e.g.:

#/dev/null so strace output is more readable
open my $fh, ">/dev/null";
select $fh;
$| = 1;

{
 print "enter";
 local *FH;
 open FH, $0;
 print "leave"
}

print "done";

% strace ~/test/io.pl
write(3, "enter", 5)                    = 5
-> open("/home/dougm/test/io.pl", O_RDONLY) = 4
fstat(4, {st_mode=S_ISGID|S_ISVTX|0401, st_size=0, ...}) = 0
fcntl(4, F_SETFD, FD_CLOEXEC)           = 0
write(3, "leave", 5)                    = 5
-> close(4)                                = 0
write(3, "done", 4)                     = 4


Reply via email to