[sf-perl] Bad file number

Quinn Weaver quinn at fairpath.com
Fri Jun 22 07:46:16 PDT 2007

On Thu, Jun 21, 2007 at 09:45:45PM -0700, Steve Fink wrote:
> 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

Actually, I agree.  I think that placing warn statements after close
(warn "just closed file $MY_PATH") will be more useful than checking
the return code--because, as you pointed out, the most likely problem
is that the close code is just failing to get called, due to bad logic.

Quinn Weaver, independent contractor  |  President, San Francisco Perl Mongers
http://fairpath.com/quinn/resume/     |  http://sf.pm.org/

More information about the SanFrancisco-pm mailing list