subroutine

Discussion in 'Perl Misc' started by weberw@adelphia.net, Jul 20, 2006.

  1. Guest

    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;
     
    , Jul 20, 2006
    #1
    1. Advertising

  2. Guest

    wrote:
    [ a multi-posted question ]

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

    --
    David Filmer (http://DavidFilmer.com)
     
    , Jul 20, 2006
    #2
    1. Advertising

  3. Guest

    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)
     
    , Jul 20, 2006
    #3
  4. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 21, 2006
    #4
  5. robic0 Guest

    On Thu, 20 Jul 2006 18:17:15 -0500, Tad McClellan <> wrote:

    > <> 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]
     
    robic0, Jul 21, 2006
    #5
  6. Guest

    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?
     
    , Jul 21, 2006
    #6
  7. Mumia W. Guest

    On 07/21/2006 03:22 PM, wrote:
    > 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.
     
    Mumia W., Jul 21, 2006
    #7
  8. Guest

    Tad McClellan wrote:
    > [a reply to ]


    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 :^)

    --
    David Filmer (http://DavidFilmer.com)
     
    , Jul 22, 2006
    #8
  9. <> wrote:
    > Tad McClellan wrote:
    >> [a reply to ]

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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 22, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey
    Replies:
    3
    Views:
    855
    Casey
    Jan 30, 2004
  2. Hon Seng Phuah
    Replies:
    1
    Views:
    478
    J├╝rgen Exner
    Mar 5, 2004
  3. Gunnar Hjalmarsson

    Subroutine definition

    Gunnar Hjalmarsson, Jun 11, 2004, in forum: Perl
    Replies:
    2
    Views:
    610
    Jim Gibson
    Jun 17, 2004
  4. Mark
    Replies:
    0
    Views:
    485
  5. king
    Replies:
    5
    Views:
    186
Loading...

Share This Page