|
Prev: flock/fcntl
Next: Find and convert to UC
From: weberw@adelphia.net on 20 Jul 2006 17:36 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;
From: usenet on 20 Jul 2006 18:00 weberw(a)adelphia.net wrote: [ a multi-posted question ] Please do not multi-post. That is considered very rude in Usenet. -- David Filmer (http://DavidFilmer.com)
From: A. Sinan Unur on 20 Jul 2006 18:10 usenet(a)DavidFilmer.com wrote in news:1153432845.843776.303160(a)i3g2000cwc.googlegroups.com: > weberw(a)adelphia.net wrote: > [ a multi-posted question ] > > Please do not multi-post. That is considered very rude in Usenet. That is my he is in my killfile permanently. Every question he has posted so far has been multiposted: http://groups.google.com/groups/profile?enc_user=Hee32RMAAAB3yPvf45KeT4uwH92YEqXUh-kUg4S0n7nbF1Te82ZIng Sinan -- A. Sinan Unur <1usa(a)llenroc.ude.invalid> (remove .invalid and reverse each component for email address) comp.lang.perl.misc guidelines on the WWW: http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
From: usenet on 20 Jul 2006 18:13 A. Sinan Unur wrote: > That is why he is in my killfile permanently. > Every question he has posted so far has been multiposted: Ah. Indeed. I will never offer assitance to this person again. -- David Filmer (http://DavidFilmer.com)
From: Tad McClellan on 20 Jul 2006 19:17
weberw(a)adelphia.net <weberw(a)adelphia.net> wrote: > while ( my @elements = $sth->fetchrow() ) { ^^^^^^^^ The DBI module does not export a method named fetchrow(). This is not your real code. > $OT = &calculateOT(emp_hours); You should not use an ampersand on subroutine calls unless you know what using an ampersand on subroutine calls does, and what it does is what you want to do. Variables in Perl start with a sigil character. This is not your real code either. $OT = calculateOT( $emp_hours ); You should consider hiring a programmer to do your programming for you, you do not appear to have an aptitude for it. -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas |