http://www.perlmonks.org?node_id=373935


in reply to Save results on web page to doc or txt

It's not clear what you're trying to do here: it would help if you broke the problem down into small parts and told us where you're stuck, maybe sharing some of the things you have tried. You might find How to ask questions the smart way. helpful for getting the most out of this site.

Here's my guess at what you want to do:

  1. Display an HTML form to the user.
  2. Process the user's input.
  3. Generate feedback as plain text or a Word document.
  4. Return this feedback to the user somehow.

Assuming I've guessed correctly, you can perform each of these stages as follows:

  1. Use a templating system (you mention Embperl) to generate the form, filling in data as required. Alternatively, use CGI's HTML output features.
  2. Write a handler using CGI, mod_perl or whatever you use.
  3. You will find plain text easier and more widely supported. If you want prettier layout, use RTF or PDF instead. Only use Word documents if you absolutely must: in general you'll find RTF an acceptable, better supported substitute.
  4. Either return the document directly from your handler, setting the appropriate MIME type in the Content-type HTTP header field, or write the file to disk and reference it with a hyperlink. If you reference the file, you should write a cron job to clear up old files.