niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl
subroutine
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
weberw@adelphia.net
*nix forums beginner


Joined: 09 Jul 2006
Posts: 22

PostPosted: Thu Jul 20, 2006 9:36 pm    Post subject: subroutine Reply with quote

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

PostPosted: Thu Jul 20, 2006 10:00 pm    Post subject: Re: subroutine Reply with quote

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

PostPosted: Thu Jul 20, 2006 10:10 pm    Post subject: Re: subroutine Reply with quote

usenet@DavidFilmer.com wrote in news:1153432845.843776.303160@i3g2000cwc.googlegroups.com:

Quote:
weberw@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@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
Back to top
usenet@DavidFilmer.com
*nix forums Guru


Joined: 25 Jul 2005
Posts: 545

PostPosted: Thu Jul 20, 2006 10:13 pm    Post subject: Re: subroutine Reply with quote

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

PostPosted: Thu Jul 20, 2006 11:17 pm    Post subject: Re: subroutine Reply with quote

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

PostPosted: Thu Jul 20, 2006 11:59 pm    Post subject: Re: subroutine Reply with quote

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

PostPosted: Fri Jul 21, 2006 2:30 pm    Post subject: Re: subroutine Reply with quote

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". Smile
-- Larry Wall in <199811242002.MAA26850@wall.org>
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Thu Aug 28, 2008 5:40 pm | All times are GMT
navigation Forum index » Programming » Perl
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts FAQ 4.67 Why does passing a subroutine an undefined eleme... PerlFAQ Server Perl 0 Sun Jul 02, 2006 7:03 am
No new posts How to pass an array and scalar as arguments to a subrout... TheOrangeRemix Perl 5 Wed Jun 28, 2006 4:16 pm
No new posts How to select subroutine Jan Fure Perl 10 Tue Jun 20, 2006 10:32 pm
No new posts Problem with passing array to subroutine benkasminbullock@gmail.co Perl 11 Thu May 25, 2006 2:51 pm
No new posts subroutine doesn't seem to run after calling it. Spin Perl 1 Tue May 09, 2006 8:04 pm

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
[ Time: 0.1360s ][ Queries: 16 (0.0494s) ][ GZIP on - Debug on ]