• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

No output with form

If you look at my code below and if you click the link to test it out, it will not output anything and I am not sure why..any suggestions?

Thanks,

Ryan

#!/usr/bin/perl

use CGI qw(:standard);
print "Content-type:text/html \n\n";


# || symbol used for use param or 0.00 instead of using if else

    my $cost = param('cost')         || '0.00';         # cost of car
    my $payment = param('payment')   || '0.00';         # payment
    my $interest = param('interest') || '0.10';         # interest rate
    my $down = param('down')         || ($cost * 0.20); # down payment on car
    my $loan = param('loan')         || '5.00';         # loan in years
    my $due;                                            # amount due

# calculations for figuring loan

    if ($interest > 1) {
        $due = ($cost - $down) * (1 + $loan * $interest / 100);
       
        # sprintf() used for decimal value - gets rid of trailing number points
        # http://perldoc.perl.org/functions/sprintf.html
       
        $interest = sprintf ("%.2f", $interest) . "%";
    } else {
        $due = ($cost - $down) * (1 + $loan * $interest);
        $interest = sprintf ("%.2f", $interest * 100) . "%";
    }


      # commify used for creating commas commify()
      # http://www.perturb.org/display/entry/562/
     
    my $month = "\$" . commify(sprintf ("%.2f", ($due / (12 * $loan))));

    $cost = "\$" . commify(sprintf ("%.2f", $cost));
    $payment = "\$" . commify(sprintf ("%.2f", $payment));
    $down = "\$" . commify(sprintf ("%.2f", $down));
    $loan = $loan . " years"; #  . " years"; used for concating and adding on X years

      # start output
     
        my $output = <<_END_;

      <table width="100%" border="1" cellpadding="5">
      <tr>
            <td width="150">Cost:</td>
            <td>$cost</td>
      </tr>
      <tr>
            <td width="150">Payment</td>
            <td>$payment</td>
      </tr>
      <tr>
            <td width="150">Interest</td>
            <td>$interest</td>
      </tr>
      <tr>
            <td width="150">Down</td>
            <td>$down</td>
      </tr>
      <tr>
            <td width="150">Loan</td>
            <td>$loan</td>
      </tr>
      <tr>
            <td width="150">Per Month:</td>
            <td>$month</td>
      </tr>
</table>

_END_
print $output;
     

And if you go to:

http://elan.champlain.edu/~rcoughlin32001/carcalculator.html

You will see a blank if you fill it out:

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Car Calculator</title>
</head>

<body>

<form name="calc" action="cgi-bin/carcalculator-ee.cgi" method="post">

<label for="cost">Vehicle Cost:</label><input type="text" name="cost" size="15" /><br />
<label for="payment">Monthly Payment:</label><input type="text" name="payment" size="15" /><br />
<label for="interest">Interest Rate:</label><input type="text" name="interest" size="15" /><br />
<label for="down">Down Payment:</label><input type="text" name="down" size="15" /><br />
<label for="loan">Years in loan:</label><input type="text" name="loan" size="15" /><br />

<input type="submit" name="submit" value="Caclulate" />

</form>

</body>
</html>

END CODE
0
catonthecouchproductions
Asked:
catonthecouchproductions
  • 3
  • 3
1 Solution
 
jasonsbytesCommented:
you are referencing a sub routine that is not in your script:

"commify"

at the bottom of your cgi below your print $output;  add this sub:

sub commify {
        my $input = shift;
        $input = reverse $input;
        $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
        return reverse $input;
}


That should fix it.
0
 
jasonsbytesCommented:
like this:

_END_
print $output;

sub commify {
        my $input = shift;
        $input = reverse $input;
        $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
        return reverse $input;
}


oh and here it is working:
http://postpoems.com/ttt.html
0
 
catonthecouchproductionsAuthor Commented:
Thank you so much!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
catonthecouchproductionsAuthor Commented:
Could you break down that last segment of code for I can see what each means? Want to learn some code.

Ryan
0
 
jasonsbytesCommented:
it's using regular expressions to match groups of digits and add in commas.  google perl regex for some tutorials...  there is far more to learn about regex than i could describe here... :)  far more than i even know myself.  

There are entire books on the subject in fact.  Have fun! :)

Glad i was able to help!
0
 
catonthecouchproductionsAuthor Commented:
Thank you very much for all of this!

Ryan
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now