nouse4anick has asked for the wisdom of the Perl Monks concerning the following question:

I want to take a text file (with only ascii text), and whenever someone loads a webpage the page then takes the contents of the text file and dumps it into the page in a spot. Thanks for any help given, Art
  • Comment on Reading from a text file for cgi output

Replies are listed 'Best First'.
Re: Reading from a text file for cgi output
by Ionizor (Pilgrim) on Jul 03, 2003 at 23:30 UTC

    You may want to look into Server Side Includes for this. Server side includes allow you to insert arbitrary text (or HTML, or sometimes scripts) into a webpage by adding an include directive inside HTML comment tags, e.g. <!--#include virtual="/includes/header.txt"-->.

    Most web servers support this but if you aren't the server administrator you may find that it has been disabled for security reasons. Definitely do some research before you leap into this method since you could open up security holes depending on the configuration of the server.

    --
    Grant me the wisdom to shut my mouth when I don't know what I'm talking about.

Re: Reading from a text file for cgi output
by revdiablo (Prior) on Jul 03, 2003 at 22:48 UTC

    Isn't that generally the very function web servers were created to perform? :)

    Take a look at open and print to see how to do this with perl, though I really am at a loss to find a reason anybody wants to do this with a CGI. I mean... really... that's what web servers do. They serve files over the web.

    Update: On re-reading, I think what you want to do is include a text file inside another web page. This seems like a bit more reasonable use for a CGI. Apologies for the assumption -- reading about open and print should steer you in the right direction.

Re: Reading from a text file for cgi output
by vek (Prior) on Jul 04, 2003 at 02:09 UTC

    Show us your code and the specific problem you are running into and we'll try and help you out.

    You didn't think we were going to do all the work for you did you?

    -- vek --