Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Bad File Descriptors Gone Wild

by chaoticset (Chaplain)
on Nov 04, 2001 at 02:07 UTC ( #123094=perlquestion: print w/ replies, xml ) Need Help??
chaoticset has asked for the wisdom of the Perl Monks concerning the following question:

Okay, that's a shameless attempt to tie this post to those stupid 'gone wild' videos. But, seriously, this has to do with bad file descriptors.

In my CGI script, I open a couple different files a couple different ways, and I created subroutines for these openings and closings.

This code:

sub stock_close { close(STOCK) || die "Error Closing Stock File: $!\n"; }

produces this output at the end of all the HTML that pops out:

Error Closing Stock File: Bad file descriptor

I already looked at this but it doesn't seem to be the same problem, because I'm not trying to open a directory.

I'm pretty much just confused about this. Am I opening the file incorrectly somehow?

Thank you for your time in advance.

-----------------------
You are what you think.

Update: Found my error. I had closed STOCK twice. I didn't really know what could produce that error.

Edited 2001-12-06 by dvergin to add update per user request</link>

Comment on Bad File Descriptors Gone Wild
Download Code
Re: Bad File Descriptors Gone Wild
by Fastolfe (Vicar) on Nov 04, 2001 at 03:14 UTC
    This probably means STOCK was not opened at the time you attempted to close it. Without more information, it's impossible for us to tell you why.

    Be sure that you're checking the return value from your open call so that you're sure STOCK was, in fact, opened.

Re: Bad File Descriptors Gone Wild
by converter (Priest) on Nov 04, 2001 at 03:34 UTC

    You can use fileno to find out if a filehandle is open, but it's a much better idea to make sure the open() succeeded in the first place, as suggested above.

    Note: the 'fileno' documentation referred to on perlmonks.org is incomplete. The documentation included with perl 5.6.1 includes this: Returns the file descriptor for a filehandle, or undefined if the filehandle is not open.

    Example:

    sub chk_hndl { if (fileno $_[0]) { print "OPEN\n" } else { print "NOT OPEN\n" } } chk_hndl(*FOO); chk_hndl(*STDOUT); # prints: NOT OPEN OPEN

    conv

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://123094]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2014-10-21 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (100 votes), past polls