CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Making a script web readable

 



yim11
Novice

Sep 6, 2000, 8:51 PM

Post #1 of 3 (412 views)
Making a script web readable Can't Post

Hello!

I have a perl script (that calculates how much a worker makes on break) that runs great from the command line. I would like to make this script available on our website. My question is what changes need to be made to the script to make it "web-firendly" . . . i.e. will take users input from a webpage and make the same calculations.

Thanks for all help!
Jim


fashimpaur
User / Moderator

Sep 7, 2000, 4:51 AM

Post #2 of 3 (412 views)
Re: Making a script web readable [In reply to] Can't Post

Yim11,

First, you need to get the form variables from the CGI Environment on the server. Then, make your calculations and print the
output in HTML back to the client browser.

Here is a simple example:

'HTML FORM'
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



<HTML><HEAD><TITLE>Break Calculations</TITLE></HEAD>
<BODY>
<FORM method=POST action="cgi-bin/breakwages.pl">
Hourly Wage <INPUT type="text" name="wages"><br>
Minutes on Break <INPUT type="text" name="minutes"><br><br>
<INPUT type="submit" name="btnSubmit" value="Calculate">
</FORM>
</BODY>
</HTML>

</pre><HR></BLOCKQUOTE>

Then write a perl script something like this:

breakwages.pl
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



#!/usr/local/bin/perl

use CGI;

$q = new CGI;
$wages = $q->param('wages');
$minutes = $q->param('minutes');

$earnings = ($wages/60)* $minutes;

print $q->header('text/html'); # edited here, forgot 'print' Smile

$htmlOut = qq~
<HTML>
<HEAD>
<TITLE>Wages On Break</TITLE>
</HEAD>
<BODY>
You earned $earnings while you were on break!
</BODY>
</HTML>~;

print $htmlOut;
exit;

</pre><HR></BLOCKQUOTE>

That is the gist of doing CGI interaction with a web form.

HTH,

Dennis

[This message has been edited by fashimpaur (edited 09-07-2000).]


yim11
Novice

Sep 7, 2000, 5:57 AM

Post #3 of 3 (412 views)
Re: Making a script web readable [In reply to] Can't Post

Dennis,
Thats what I thought I would have to do. Thank You Very Much for showing me the syntax! Everything works great!

Thanks Again!
-Jim

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives