The below script works just fine from a command prompt but never when it’s called from a web browser.

You don't mention what web server you're using, and that can make a big difference in one of several ways. First, different web servers are inconsistent in what working directory they launch scripts in. You'd expect that to be whatever directory the script itself is, but that's not always the case. (I recall pulling my hair out when trying to debug a script on Netscape FastTrack.)

Further, different OS/Web Server combinations have different notions of permissions. Since your problem may be one of writing, chances are good that you're using Apache on Unix or a Unix variant (e.g., Linux, FreeBSD). Here, to write a temporary file, the directory that holds the CGI must have a permission that allows whatever user the web server is running under to create a file. This isn't a "best practice". Better is to create a subdirectory that will hold only data, giving that subdirectory a "world writable" permission, and then creating the temporary file in that directory. Assuming that writeable subdirectory is "data", changing your code to

open(DA, ">", "data/date.tmp") or die "data/date.tmp: $!";
should be sufficient. The three-argument form of open() makes it explict that you're trying to create a file. The "or die" part will provide you with valuable information in your server logs should things fail.


In reply to Re: Runs from console but not as CGI - temp file not created by dws
in thread Runs from console but not as CGI - temp file not created by Anonymous Monk

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.