1 / 17

Building PERL Scripts on a Windows system*

Building PERL Scripts on a Windows system*. *and running those scripts on an Apache server!. Tools Used. Windows XP service pack 3 computer GoDaddy account for hosting Domain name Filezilla for FTP access DOS to Unix conversion tool. The Dilemma.

Download Presentation

Building PERL Scripts on a Windows system*

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!

  2. Tools Used • Windows XP service pack 3 computer • GoDaddy account for hosting • Domain name • Filezilla for FTP access • DOS to Unix conversion tool

  3. The Dilemma • I wanted to further master my web programming skills after completing HTML, Javascripting and PHP courses at Chaffey • I signed up for Perl/CGI • Hosted my website www.nickburns.com with GoDaddy after discussing my needs with them • I then found for CGI, they use an Apache server! • This created the need to learn how to convert DOS (Windows) derived files into Unix/Linux files so the server would be able to run them correctly

  4. The Solution • I found, after quite a bit of searching and testing, a simple and powerful utility which will translate “fromDOS” or “toDOS” based on the user’s needs • Now, the process…

  5. Build a Set of Files • Build the html page first • Point the html to the cgi file • Upload the HTML page to the web server • Build the CGI file(s) • Convert the cgi file(s) into Unix type file(s) • Upload the converted cgi to the web server using Filezilla • Change the cgi file attributes to 755 • Disconnect from the server • Test by connecting to the html web page

  6. HTML Page • <!book.html> • <HTML> • <HEAD><TITLE>Jubilee Book Club</TITLE></HEAD> • <BODY> • <H1 ALIGN=center>Jubilee Book Club Home Page</H1><HR> • <H2 ALIGN=center>Click the book to sign in<BR> • <A HREF="/cgi/book1.cgi"> Points to the CGI file • <IMG SRC=book.jpg></A></H2> • </BODY></HTML>

  7. CGI Script (yes, it is a bit small; bear with me) #!/usr/bin/perl #book1.cgi - displays a sign-in form print "Content-type: text/html\n\n"; use CGI qw(:standard); use strict; #declare variable my $name; #retrieve Name cookie $name = cookie('Name'); print "<HTML>\n"; print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n"; print "<BODY>\n"; print "<H1>Jubilee Book Club Sign-In Form</H1><HR>\n"; print "<FORM \n"; print "ACTION='book2.cgi' \n"; print "METHOD=POST>\n"; print "<TABLE>\n"; print "<TR><TD>Name:</TD><TD>\n"; print "<INPUT TYPE=text NAME=Name SIZE=25 VALUE='$name'>\n"; print "</TD></TR>\n"; print "</TABLE>\n"; print "<BR><INPUT TYPE=submit VALUE=Submit>\n"; print "</FORM></BODY></HTML>\n";

  8. CGI Script Described • Shebang line • UNIX – #!/usr/bin/perl (be very careful to get this right; I once spent hours debugging a script only to discover I had typo’d on this line) • File name and description of what the file will perform - #book1.cgi - displays a sign-in form • Declare the type of page - print "Content-type: text/html\n\n"; - HTML for example • Use the # for comments

  9. CGI Script Described (continued) • Use declarations - use CGI qw(:standard); - to tell Perl what module to use • Prevent Perl from creating undeclared - use strict; • Perl statements end with a semi-colon • Declare variable - my $name; • Add a cookie -$name = cookie('Name');

  10. CGI Script Described (continued) • Print/Return an HTML page • Code in much the same way as a standard HTML page with print statements: • print "<HTML>\n"; • print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n"; • print "<BODY>\n"; • print "<H1>Jubilee Book Club Sign-In Form</H1><HR>\n"; • print "<FORM \n"; • print "ACTION='book2.cgi' \n"; • print "METHOD=POST>\n";

  11. CGI Script Described (continued) • print "<TABLE>\n"; • print "<TR><TD>Name:</TD><TD>\n"; • print "<INPUT TYPE=text NAME=Name SIZE=25 VALUE='$name'>\n"; • print "</TD></TR>\n"; • print "</TABLE>\n"; • print "<BR><INPUT TYPE=submit VALUE=Submit>\n"; • print "</FORM></BODY></HTML>\n"; • Remember to close each object! • This cgi also points to a 2nd cgi file containing the cookie, which will greet the customer

  12. CGI Script Described (continued) • Open the 2nd CGI file in same manner as the first with a different file name: • #!/usr/bin/perl • #book2.cgi - displays a Web page containing the user's • #name and the book information • use CGI qw(:standard); • use strict; • #declare variables • my ($name, $C_name); • #assign input to variable • $name = param('Name');

  13. CGI Script Described (continued) • Create the cookie: • $C_name = cookie(-name => "Name", (input from the form) -value => "$name", (variable to save) -path => "/cgi", (path where to save the cookie) -expires => "+6M"); (how long to save the cookie) • Send the cookie to the browser: • print header(-cookie => $C_name);

  14. CGI Script Described (continued) • Create the response web page: • print "<HTML>\n"; • print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n"; • print "<BODY>\n"; • print "<H1 ALIGN=center>Hello, $name!<BR>\n"; • print "The book of the month is</H1><HR>\n"; • print "<H2 ALIGN=center><FONT COLOR=red>\n"; • print "<I>The Case of the Missing Dagger</I>\n"; • print "<BR>by H.T. Sims\n"; • print "</FONT></H2>\n"; • print "</BODY></HTML>\n"; • Script is now complete

  15. Format the CGI File(s) • After following the simple directions in their readme file and installing “fromDOS” • Open a command prompt • Change directory to the location of the cgi file(s) • Type fromDos filename.cgi and press Enter • The file is now compatible with Unix • Type perl –c filename.cgi and press Enter • Perl starts the perl interpreter • -c checks the syntax without executing • If no errors, proceed to upload

  16. Uploading the CGI files • Open Filezilla • Set up a connection to the server with appropriate user name and password • Left side window is location of local files • Right side window is location of server side files • Usually cgi-bin is the desired directory for cgi files, but GoDaddy uses CGI as their directory • Upload the converted files to the server’s CGI folder • Right click on the server files and select File Attributes • Change attributes to 755 and disconnect when complete

  17. Testing • Open a Browser • Connect to the path of the HTML file uploaded • Complete the form as necessary • Determine if the results are as expected • Finished

More Related