Perl Basics - Part 4

Sending information back to the user

There are only a couple of basic things you'll need to know to send appropriate information back to the user:
print commands
Generally, print commands will send information to the STDOUT, which will get passed directly to the user's browser. This is generally what you want to do (see Content-type below). In more advanced Perl applications, you may want to print some information to a file, in which case you'll have to be aware of where your print commands are sending information.
Header information
The HTTP standard includes header information which tells the browser what to do with the information it receives. The browser will interpret everything it receives, up until the first blank line, as header information. You will always need to provide outgoing header information with user output.
  1. Content-type
    • This is a borrowed element from the MIME standard. The browser at the recieving end doesn't know what sort of information it's going to get in response to the query it just sent, so you have to tell it. Generally, you'll always want the first thing printed to be "Content-type: text/html\n\n"; (notice the two newlines; one of them is the blank line which seperates header from body). Anything you print after that will be interpretted by the user's browser as HTML, just as if it had come from a regular HTML text file. You'll notice the text/html format is just like the MIME-type listed in the Helper Applications preference of many graphical browsers.
  2. Location
    • Sometimes you won't want to print your own HTML to a user, but will want to send that user to some other URL. You can use the Location header to do that. If you print "Location: http://www.itp.tsoa.nyu.edu/\n\n"; with nothing else (no other HTML or "Content-type" or anything), the user's browser will send a request to the specified server for the page at that URL.


OK, Jamie, if your so smart, don't you ever have any problems?

Tell me about the Form input stuff again...