grosspostenv.html

 

<html>

<head><title>Spruce Department Store</title></head>

<body>

<div align=center>

<h1>Get Pay Information</h1>

<img src="spruce.gif">

</div>

<form action="http://www.pgrocer.com/cgi-bin/misc/grossparenv.cgi" method=post>

Employee Name:

<input name=Employee Size=20><br><br>

Pay per Hour:

<input name=PayHour Size=5><br><br>

Hours Worked:

<input name=NumHours Size=5><br><br>

Bonus:

<input name=Bonus Size=5><br><br>

<input type=submit value=Submit><br>

<input type=reset value=Reset>

</form>

</body>

</html>

 

grossparenv.cgi

 

#!/usr/bin/perl

#grossparenv.cgi - computes gross pay and a dynamic web page

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

use CGI qw(:standard);

#avoid undeclared variables

use strict;

#declare variables

my($name, $payhr, $hours, $bonus, $gross, $grossyr, $msg, $thehost, $theuser);

$name = param('Employee');

$payhr = param('PayHour');

$hours = param('NumHours');

$bonus = param('Bonus');

#calculate gross pay

$gross = $payhr * $hours;

$grossyr = $payhr * $hours * 52 + $bonus;

if ($ENV{'REQUEST_METHOD'} eq "POST")

{

$msg = "Yes it is POST";

}

else

{

$msg = "No it is not POST";

}

$thehost = $ENV{'HTTP_HOST'};

$theuser = $ENV{'HTTP_USER_AGENT'};

#create gross pay web page

print "<html>\n";

print "<head><title>Gross Pay</title></head>\n";

print "<h1>Calculate Gross Pay</h1>\n";

print "<body>\n";

print "Employee: $name<br>\n";

print "Pay rate: $payhr<br>\n";

print "Hours: $hours<br>\n";

print "Gross pay: $gross<br>\n";

print "Yearly gross pay: $grossyr<br>\n";

print "Message is: $msg<br>\n";

print "The host is: $thehost<br>\n";

print "The browser is: $theuser<br>\n";

print "</body>\n";

print "</html>\n";

 

stringfunctr.cgi

 

#!/usr/bin/perl

#grossparenv.cgi - computes gross pay and a dynamic web page

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

use CGI qw(:standard);

#avoid undeclared variables

use strict;

#declare variables

my($name, $payhr, $hours, $bonus, $gross, $grossyr, $msg, $thehost, $theuser);

$name = param('Employee');

$payhr = param('PayHour');

$hours = param('NumHours');

$bonus = param('Bonus');

#calculate gross pay

$gross = $payhr * $hours;

$grossyr = $payhr * $hours * 52 + $bonus;

if ($ENV{'REQUEST_METHOD'} eq "POST")

{

$msg = "Yes it is POST";

}

else

{

$msg = "No it is not POST";

}

$thehost = $ENV{'HTTP_HOST'};

$theuser = $ENV{'HTTP_USER_AGENT'};

#create gross pay web page

print "<html>\n";

print "<head><title>Gross Pay</title></head>\n";

print "<h1>Calculate Gross Pay</h1>\n";

print "<body>\n";

print "Employee: $name<br>\n";

print "Pay rate: $payhr<br>\n";

print "Hours: $hours<br>\n";

print "Gross pay: $gross<br>\n";

print "Yearly gross pay: $grossyr<br>\n";

print "Message is: $msg<br>\n";

print "The host is: $thehost<br>\n";

print "The browser is: $theuser<br>\n";

print "</body>\n";

print "</html>\n";

 

stringfunctrmore.cgi

 

#!/usr/bin/perl

#stringfunctrmore.cgi - reads the payroll file and processes with functions

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

use CGI qw(:standard);

use strict;

#declare variables

my ($id, $name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);

open(INF, "<", "payroll1.txt")

or die "file error: payroll1.txt. $!, stopped";

while(<INF>) {

chomp($_);

($name,$stadr,$city,$state,$zip,$jobtype,$jobcode,$payperhr,$salary) = split(/,/,$_);

createid();

print "The id is: $id <br> The name is: $name<br>\n";

}

close(INF);

print "</body></html>\n";

exit;

#********user defined functions****************

sub createid

{

my($namefst3, $stateup, $citymid, $jc3, $num, $amt, $word);

$namefst3 = lcfirst(substr($name,0,3));

$stateup = lc($state);

$stateup =~ tr/a-z/A-Z/;

$citymid = lc(substr($city,3,2));

$jc3 = $jobcode x 3;

$num = ($jc3 =~ tr/3/*/);

$amt = "\$123,456";

$amt =~ tr/$,//d;

$word = "FOX ";

$word =~ tr///s;

$id = $namefst3.$stateup.$jc3.$num.$citymid.$word.$amt;

return $id;

}

 

stringfuncmatch.cgi

 

#!/usr/bin/perl

#stringfuncmatch.cgi - reads the payroll file and processes with functions

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

use CGI qw(:standard);

use strict;

#declare variables

my ($id, $name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);

open(INF, "<", "payroll1.txt")

or die "file error: payroll1.txt. $!, stopped";

while(<INF>) {

chomp($_);

($name,$stadr,$city,$state,$zip,$jobtype,$jobcode,$payperhr,$salary) = split(/,/,$_);

createid();

print "The id is: $id <br> The name is: $name<br>\n";

}

close(INF);

print "</body></html>\n";

exit;

#********user defined functions****************

sub createid

{

my($namefst3, $statelc, $citymid,$jc3, $idwk);

$namefst3 = lcfirst(substr($name,0,3));

$statelc = lc($state);

$citymid = lc(substr($city,3,2));

$jc3 = $jobcode x 3;

$idwk = $namefst3.$statelc.$jc3.$citymid;

if ($idwk =~ m/111/)

{

$id = $idwk.$statelc;

}

else

{

$id = $idwk.$citymid;

}

return $id;

}