[sf-perl] Bad file number

Steve Fink sphink at gmail.com
Thu Jun 21 21:45:45 PDT 2007


On 6/21/07, Quinn Weaver <quinn at fairpath.com> wrote:
> On Thu, Jun 21, 2007 at 02:30:40PM -0700, Loo, Peter # PHX wrote:
> > I have checked the logic and it appears that there is a
> > corresponding close() for every open().  I don't know why Perl is
> > warning me with this error.
>
> Just "checking the logic" by looking at your code doesn't cut it.
> You need to test empirically whether your code is doing what you think it is.
>
> Try putting warn "closed file MYFILE successfully" after your close
> statements... just to verify that what you think is happening is
> actually happening.
>
> Make a habit of testing your assumptions this way.  It is the royal
> road to figuring out bugs.  Debugging is a matter of practice, not theory--
> because if the code were working the way that you think in theory
> it should be, you wouldn't have a bug!

Good general advice, but I'm not sure how well it applies in this
situation. How many ways can close() fail in such a way that the file
descriptor is not closed? If it did, what would the user be able to do
about it? (There are many ways for close() to fail, as many as there
are ways that write() can fail, but close() should still close the
fd.)

There *is* actually one way, if close() returned EINTR, but I doubt
that's what is happening here. I'm guessing the logic isn't quite
right. Checking the result of close() may indeed point out valuable
clues, though. (eg if it is returning EINVAL, perhaps you're not
closing what you think.)


More information about the SanFrancisco-pm mailing list