In my recent Perl class we constructed a Perl/CGI script that read a list of produce items from a text file, then used those items to make a web order form. This code ran perfectly on the class Unix server.

Now I've returned home and I uploaded the same script and the same text file to my website's server. Now when I run the script it fails with an error:

Error opening produce_items.txt! : No such file or directory at /html/cgi/eproduce.cgi line 24.

First of all, here's the code I'm using:

#===== Open the file containing our list of produce $filename = "produce_items.txt"; open(PRODUCE, $filename) || die "Error opening $filename! : $!\n ";

Someone suggested trying the full pathname, so I amended the code as follows:

#===== Open the file containing our list of produce $current_directory = $ENV{PWD}; $filename = "$current_directory" . "/" . "produce_items.txt"; open(PRODUCE, $filename) || die "Error opening $filename! : $!\n ";

This fails with the same error (well, slightly different... it says "/produce_items.txt" instead of "produce_items.txt").

The text file is in the same directory as the cgi file, by the way.

I know this is a CGI problem, not a Perl problem, but perhaps someone more experienced than I can see what I'm doing wrong?

Many thanks!

Charles Thomas
Madison, WI

In reply to Slightly OT: Perl and CGI - reading a file by C_T

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.