[sf-perl] Bad file number
quinn at fairpath.com
Thu Jun 21 17:55:29 PDT 2007
On Thu, Jun 21, 2007 at 02:30:40PM -0700, Loo, Peter # PHX wrote:
> I am getting a "Too many open files" error when the program attempts to
> open a file.
It's possible that your calls to close() are failing silently. Close
returns a true value on success and a false value on failure. So you
can add code to check its return value, to see if it's really working.
close MY_FH or warn "Couldn't close file: $!";
> 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
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!
Quinn Weaver, independent contractor | President, San Francisco Perl Mongers
http://fairpath.com/quinn/resume/ | http://sf.pm.org/
More information about the SanFrancisco-pm