|
|
|
|
|
|
| Author |
Message |
weberw@adelphia.net *nix forums beginner
Joined: 09 Jul 2006
Posts: 22
|
Posted: Thu Jul 20, 2006 9:36 pm Post subject:
subroutine
|
|
|
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; |
|
| Back to top |
|
 |
usenet@DavidFilmer.com *nix forums Guru
Joined: 25 Jul 2005
Posts: 545
|
Posted: Thu Jul 20, 2006 10:00 pm Post subject:
Re: subroutine
|
|
|
weberw@adelphia.net wrote:
[ a multi-posted question ]
Please do not multi-post. That is considered very rude in Usenet.
--
David Filmer (http://DavidFilmer.com) |
|
| Back to top |
|
 |
A. Sinan Unur *nix forums Guru
Joined: 03 Mar 2005
Posts: 1840
|
|
| Back to top |
|
 |
usenet@DavidFilmer.com *nix forums Guru
Joined: 25 Jul 2005
Posts: 545
|
Posted: Thu Jul 20, 2006 10:13 pm Post subject:
Re: subroutine
|
|
|
A. Sinan Unur wrote:
| Quote: | 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) |
|
| Back to top |
|
 |
Tad McClellan *nix forums Guru
Joined: 09 Mar 2005
Posts: 1647
|
Posted: Thu Jul 20, 2006 11:17 pm Post subject:
Re: subroutine
|
|
|
weberw@adelphia.net <weberw@adelphia.net> wrote:
| Quote: | while ( my @elements = $sth->fetchrow() ) {
^^^^^^^^ |
The DBI module does not export a method named fetchrow().
This is not your real code.
| Quote: | $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@augustmail.com Perl programming
Fort Worth, Texas |
|
| Back to top |
|
 |
robic0@nirgendwo *nix forums Guru
Joined: 10 Nov 2005
Posts: 701
|
Posted: Thu Jul 20, 2006 11:59 pm Post subject:
Re: subroutine
|
|
|
On Thu, 20 Jul 2006 18:17:15 -0500, Tad McClellan <tadmc@augustmail.com> wrote:
| Quote: | weberw@adelphia.net <weberw@adelphia.net> wrote:
while ( my @elements = $sth->fetchrow() ) {
^^^^^^^^
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] |
|
| Back to top |
|
 |
Brian Raven *nix forums beginner
Joined: 02 Jun 2006
Posts: 3
|
Posted: Fri Jul 21, 2006 2:30 pm Post subject:
Re: subroutine
|
|
|
Tad McClellan <tadmc@augustmail.com> writes:
| Quote: | weberw@adelphia.net <weberw@adelphia.net> wrote:
while ( my @elements = $sth->fetchrow() ) {
^^^^^^^^
The DBI module does not export a method named fetchrow().
This is not your real code.
|
I find this in DBI.pm version 1.51:
%DBI::DBI_methods = ( # Define the DBI interface methods per class:
....
st => { # Statement Class Interface
....
fetch => undef, # alias for fetchrow_arrayref
fetchrow_arrayref => undef,
fetchrow_hashref => undef,
fetchrow_array => undef,
fetchrow => undef, # old alias for fetchrow_array
HTH
--
Brian Raven
That being said, I think we should immediately deprecate any string
concatenation that combines "19" with "99".
-- Larry Wall in <199811242002.MAA26850@wall.org> |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Aug 28, 2008 5:40 pm | All times are GMT
|
|
Bad Credit Mortgages | Credit Cards | Mortgages | Car Credit | Website Design
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|