W
weberw
I am trying to incorprate a subroutine to perform an extra calculation
on overtime hours and am not sure how to add this part to the code.
$OT = &calculateOT(emp_hours);
& search_page();
my $p_lname = param('lname');
my $p_fname = param('fname');
open (THIS, "< $ENV{'SCRIPT_FILENAME'}") || die "couldn't open script
file\n";
while (<THIS>) { $script .= "$.\t$_" }
close (THIS);
$script = escapeHTML($script);
my $dbh = DBI->connect("DBI:mysql:database=thename;host=whatever", "",
"", {'RaiseError' => 1}) or die "Failed to connect: $!";
my $sth = $dbh->prepare("SELECT * FROM employee WHERE emp_lname= ? or
emp_fname= ?") or die "Failed to prepare: $!";
my @rows = th("Employee ID").th("Last Name").th("First
Name").th("Wage").th("Hours");
$sth->execute ($p_lname,$p_fname) or die "Failed to execute: $!";
while ( my @elements = $sth->fetchrow() ) {
#call a subroutine that calculates the number of OT hours
$OT = &calculateOT(emp_hours);
my $output;
for (@elements) { $output .= td($_) }
push @rows, $output."\n";
}
$dbh->disconnect or die "Failed to disconnect: $!";
print header,
start_html("Employee List"),
a( {-href=>'emp1.cgi'}, h2("Employee List") ),
table ( {-border=>'1'}, Tr(\@rows) ),
hr, pre($script),
end_html;
sub search_page {
print header,
start_html("Employee Search Form"),
h2("Employee Search Form"),
start_form,
"First Name: ",
textfield(-name=>'fname'),
br,
"Last Name: ",
textfield(-name=>'lname'),
br,
submit(-label=>'Search'),
end_form,
hr,
end_html;
}
sub calculateOT{
if (emp_hours > 40){
$OT = emp_hours-40;
}
else{
$OT = 0;
}
end_html;
on overtime hours and am not sure how to add this part to the code.
$OT = &calculateOT(emp_hours);
& search_page();
my $p_lname = param('lname');
my $p_fname = param('fname');
open (THIS, "< $ENV{'SCRIPT_FILENAME'}") || die "couldn't open script
file\n";
while (<THIS>) { $script .= "$.\t$_" }
close (THIS);
$script = escapeHTML($script);
my $dbh = DBI->connect("DBI:mysql:database=thename;host=whatever", "",
"", {'RaiseError' => 1}) or die "Failed to connect: $!";
my $sth = $dbh->prepare("SELECT * FROM employee WHERE emp_lname= ? or
emp_fname= ?") or die "Failed to prepare: $!";
my @rows = th("Employee ID").th("Last Name").th("First
Name").th("Wage").th("Hours");
$sth->execute ($p_lname,$p_fname) or die "Failed to execute: $!";
while ( my @elements = $sth->fetchrow() ) {
#call a subroutine that calculates the number of OT hours
$OT = &calculateOT(emp_hours);
my $output;
for (@elements) { $output .= td($_) }
push @rows, $output."\n";
}
$dbh->disconnect or die "Failed to disconnect: $!";
print header,
start_html("Employee List"),
a( {-href=>'emp1.cgi'}, h2("Employee List") ),
table ( {-border=>'1'}, Tr(\@rows) ),
hr, pre($script),
end_html;
sub search_page {
print header,
start_html("Employee Search Form"),
h2("Employee Search Form"),
start_form,
"First Name: ",
textfield(-name=>'fname'),
br,
"Last Name: ",
textfield(-name=>'lname'),
br,
submit(-label=>'Search'),
end_form,
hr,
end_html;
}
sub calculateOT{
if (emp_hours > 40){
$OT = emp_hours-40;
}
else{
$OT = 0;
}
end_html;