subroutine

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;
 
U

usenet

(e-mail address removed) wrote:
[ a multi-posted question ]

Please do not multi-post. That is considered very rude in Usenet.
 
U

usenet

A. Sinan Unur said:
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.
 
T

Tad McClellan

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.
 
R

robic0

^^^^^^^^

The DBI module does not export a method named fetchrow().
but he is not looking for an "exported" method, he is calling
id directly with "$sth->fetchrow", which is not what you think,
weather it exists or not.

[snip]
 
W

weberw

Sorry about double posting. I click the send button only once so I am
not sure why this is happening. Maybe because I am posting to multiple
user groups. Example, perl beginners and perl misc. Would this cause
double posting to occur?
 
M

Mumia W.

Sorry about double posting. I click the send button only
once so I am not sure why this is happening. Maybe because
I am posting to multiple user groups. Example, perl
beginners and perl misc. Would this cause double posting
to occur?

That's called multi-posting. Don't do it. People who read both
groups find it annoying, and they aren't going to be annoyed
by you for long before they blacklist you.

It's probably too late since two of the more knowledgeable
people in this newsgroup have already blocked or decided to
ignore your messages.

Too bad. I sent you a private e-mail warning you to follow the
posting guidelines for this newsgroup or you would probably be
blacklisted. It's happened. You didn't read my e-mail. You
didn't read the posting guidelines. You didn't follow the
posting guidelines.

Following the posting guidelines is not optional. Ignore the
posting guidelines and get blacklisted. That's how it works.
 
U

usenet

Tad said:
[a reply to (e-mail address removed)]

Gee, Tad, how is it that the OP is in Sinan's killfile but not yours?
I heard you need an Oracle server to host your killfile :^)
 
T

Tad McClellan

Tad said:
[a reply to (e-mail address removed)]

Gee, Tad, how is it that the OP is in Sinan's killfile but not yours?


Different people have different tolerance levels.

But this poster has now exceeded my tolerance level too, so the
killfiles are once again in sync. :-(

I heard you need an Oracle server to host your killfile :^)


I usually save the post that earned each poster their invisibility.

ls News/killed | wc -l

744

The filesystem-as-DB should suffice for several more years worth.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top