Please advise me about my logic/syntax errors. I can't seem to figure out how to write in a logical sequence this code. I'm also getting an error which I don't understand which states that m/^$first_name/ has an uninitialized variable.
-Tee
#!/usr/bin/perl -w
use CGI qw(:all); use CGI::Carp 'fatalsToBrowser'; use strict;
print header, start_html(-title=>'Employee Search'), h1('Teresa Raymond\'s Employee Search');
&search_form unless param;
if (param) { my $filename='employee.dat'; my $match; my $first_name=param('first_name'); my $last_name=param('last_name'); my $fn_weight; my $ln_weight; my $weight; my $ot_hours; my ($id, $fname, $lname, $hourly_wage, $hours_worked); my $gross_pay; my @rows; my %employees;
open (FH, $filename) or die "cannot locate $filename\n"; @rows = <FH>; close(FH);
print table({-border=>'l'}); print Tr(); print th('Weight').th('Employee ID').th('Last Name'). th('First Name').th('Hourly Wage').th('Hours Worked'). th('Overtime Hours').th('Gross Pay');
for (@rows)
{
($id, $lname, $fname, $hourly_wage, $hours_worked) = split(/\t/i);
if (my @matches = $fname =~ m/^$first_name/ig)
{
$match=scalar(@matches);
if ($hours_worked > 40)
{
$ot_hours = $hours_worked - 40;
}
else
{
$ot_hours = 0;
}
$gross_pay = &sub_calc_ot_pay($hourly_wage, $ot_hours) +
&sub_calc_normal_pay($hours_worked, $hourly_wage);
$weight = $match;
%employees = ($id => { lname => $lname,
fname => $fname,
wage => $hourly_wage,
hours_worked => $hours_worked,
ot_hours => $ot_hours,
gross_pay => $gross_pay,
weight => $weight
});
}
else
{
chomp;
}
if (my @matches = $lname =~ m/^$last_name/ig) {
$match += scalar(@matches);
if ($hours_worked > 40)
{
$ot_hours = $hours_worked - 40;
}
else
{
$ot_hours = 0;
}
$gross_pay = &sub_calc_ot_pay($hourly_wage, $ot_hours) +
&sub_calc_normal_pay($hours_worked, $hourly_wage);
$weight = $match;
%employees = ($id => { lname => $lname,
fname => $fname,
wage => $hourly_wage,
hours_worked => $hours_worked,
ot_hours => $ot_hours,
gross_pay => $gross_pay,
weight => $weight
});
}
else
{
chomp;
}
}
if ($match > 0)
{
for (keys %employees)
{
if ($employees{$_}{$fname}=~m/^$first_name/ig)
{
print Tr();
print td("$employees{$_}{$weight}").td("$id").
td("$lname").td("$fname").td("$hourly_wage").
td("$hours_worked").td("$ot_hours").
td("$gross_pay");
}
if ($employees{$_}{$lname}=~m/^$last_name/ig)
{
print Tr();
print td("$employees{$_}{$weight}").td("$id").
td("$lname").td("$fname").td("$hourly_wage").
td("$hours_worked").td("$ot_hours").
td("$gross_pay");
}
}
}
if ($match == 0)
{
print h2("Sorry there was no match for $first_name $last_name");
&sub_search_form;
}
}
sub search_form { print start_form, p('First Name: '), textfield(-name=>'first_name', -size=>'20'), p('Last Name: '), textfield(-name=>'last_name', -size=>'20'), br, submit, hr,br, ul({-type=>'disc'}, li(['John Smith', 'Jacob Jones', 'Rusty Smythe', 'Fred Artis', 'Nancy Barnes', 'Timothy Walls', 'Nigel Charma', 'Carla Rain', 'Freda Snow', 'Summer Winds', 'Sean Connery']));
print end_form, end_html; }
sub sub_calc_ot_pay { my $hourly_wage = $_[0]; my $ot_hours = $_[1]; my $ot_pay; if ( $ot_hours != 0 ) { $ot_pay = $ot_hours*1.5*$hourly_wage; } else { $ot_pay = 0; } return $ot_pay; }
sub sub_calc_normal_pay { my $normal_pay; my $hours_worked = $_[0]; my $hourly_wage = $_[1]; if ($hours_worked <= 40) { $normal_pay = $hourly_wage*$hours_worked; } else { $normal_pay = 40*$hourly_wage; }
return $normal_pay; }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>