I'm writing a CGI program (Apache running on FreeBSD) that will write some output to a file. This part is causing me no end of headaches:

sub write_list { my $outfile = "/home/foo/bar"; open (OUT, ">$outfile") or &print_error ("Can't open $outfile: + $!"); foreach $i (@changes) { print OUT $i; } close (OUT) or print_error ("Can't close $file properly: $!"); }
Opening the file is fine. Writing to the file is fine (I can cat the file and see what I expected; @changes is global, which prob. isn't the best way to do it but doesn't seem to be relevant here). Closing the file gives an error: "Error: Can't close /home/foo/bar properly: Bad file descriptor."

I've tried chmod'ing the file 777. I've tried making the group ownership www (group of the user running Apache). Both have no effect. I can't seem to find any information on this problem with close(). Can anyone fill me in on what I'm doing wrong?

I am now blessing your keyboard...


In reply to close() gives bad file descriptor error by Saint Aardvark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.