Step 3: Use perl to create HTML code (common gateway interface script)
In this step, you will use perl to create an html script that has form fields and a hyperlink. The script wont do anything but display and let you enter into the form.
Read this tutorial at: http://www.tutorialspoint.com/perl/perl_cgi.htm
Refer to Step 1 if you need to figure out your web url or the fact that you need to use public_html.
Refer to Step 2 if html form fields are new to you.
Refer to Step 1 if you do not know how to link a html page to a file
Fact you need to know: On our system, it is helpful to use these first 2 lines as the first lines in your perl CGI program and name your script with .pl extension:
#!/usr/bin/perl
print "content-type:text/html; charset=utf-8\n\n";
- The first line tells panther to treat this as a perl script
- The second line tells the browser to expect HTML code.
Fact that is helpful: There are 3 ways you can use to print lines of text (and remember that your html code is text you are printing). You only need this because printing HTML requires so many lines of text.
Here style: print <<ENDTAG ; and then write a lot on later lines and then end your block of writing with ENDTAG starting on the first character of a line.
Print qq command: print qq( whatever you put in here does not need to be surrounded by quotes ) ;
- ex: printqq(<HTML>);
Print command: put what you want to print inside double or single quotes.
- print '<HTML>';
Your job in this step:
Use Perl Print statements to write an html document that has form fields and hyperlinks. It can say anything and just has to include one form field and one hyperlink to a file.
You could convert Step 1's or Step 2's exercise result to a CGI script by
#!/usr/bin/perl
print "content-type:text/html; charset=utf-8\n\n";
Test on panther: When you run your script on panther using perl filename, it will show the html code you want the browser to see.
Test in your browser (on the internet): When you use your browser to look at this script, it will appear as the html is translated.
I am hoping you now understand how you use perl to create a web page.
This means that