Perl Web Page – Just Enough Pepper. Web site Set up the top of your script to indicate perl and...
-
Upload
edward-skinner -
Category
Documents
-
view
218 -
download
5
Transcript of Perl Web Page – Just Enough Pepper. Web site Set up the top of your script to indicate perl and...
Perl Web Page – Just Enough
Pepper
Web site• Set up the top of your script to indicate perl and
plain text#!/usr/bin/perlprint "Content-type:text/plain\n\n";
• You can put html tags which the browser will understand, or not
• Ensure that others can read and execute:–chmod o+rx yourfile.pl
• Web address–www.adelphi.edu/~pe16132/271/yourscript.pl–Must be under public_html
HelloWorld perl on internet
Print HTML code to the browser:#!/usr/bin/perlprint "Content-type:text/plain\n\n";print "content-type:text/html; charset=utf-8\n\n";
print "hello world!";
HelloWorld perl on internet
Print HTML code to the browser more cleanly:#!/usr/bin/perl print "Content-type:text/plain\n\n"; print "content-type:text/html; charset=utf-8\n\n print <<ENDHTML; <html> <head> <title>CGI Test</title> </head> <body> Hello World! <a href="http://someplace.com">Click Here</a> </body> </html>
ENDHTML
http://www.pageresource.com/cgirec/ptut4.htm
Taking in parms • Use an html form to prompt for input • Change our script to use CGI• Print out a form section of html that will run your
own script<form method="post" action="myscript.pl"><input type="test" name="input" /> <input type="submit" value="Submit /"></form>
• Retrieve from the the search word from the form
Script changes to retrieve resultsprint "content-type:text/html; charset=utf-8\n\n";use strict;use CGI qw/:standard/;my $search = param("input")||"";print qq(<!DOCTYPE html><head></head><body><form method="post" action="testinput4.pl"><label for="input">What is the search word:</label><input type="text" name="input" value="" /><input type="submit" value="Post Input" /></form>);if ($search) { print qq(<br />the search word is $search<br />); yourpage();}print qq(</body></html>);
sub yourpage {print "do whatever you want in your page here <br />";print "and you can use $search <br />";print "\n does nothing ";print "and you need to but br inside angle brackets to get the tne next line <br />";}
Summary Web
• Create a perl script that uses a preset search word input form
• Insert your code inside the yourpage method– Read your files– Display your results
• Place script in public_html• Set permissions (chmod o+rx your script.pl)• Run as www.adelphi.edu/~<your dir>/<yourscript>