in reply to Re: Catching errors in closing lexical filehandles
in thread Catching errors in closing lexical filehandles
The way I see it, I have a lexically scoped resource and when it goes out of scope, I want perl to free it for me. Of course on a low level that's exactly what it does, but the added DWIMmery of also doing something with possible errors here is just the kind of convenience I like having in Perl.
Or from a slightly different tack: if this were a c function allocating memory on the heap, with the memory only being used inside the function, obviously you'd need to free() it before returning, no matter what. You don't undef your lexicals before you exit a Perl scope, do you? I think this sort of requirement in c is what led to the stylistic recommendation of having only one exit point for functions, because cleanup tends to be simpler, at least in theory. Once you don't have that pressure, the impetus to return in only one place lessens, and (to my mind, at least) exploiting scoping to do your cleanup for you becomes more attractive.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Catching errors in closing lexical filehandles
by graff (Chancellor) on Sep 27, 2004 at 08:06 UTC | |
by gaal (Parson) on Sep 27, 2004 at 09:19 UTC |