We help IT Professionals succeed at work.

No output with form

catonthecouchproductions
on
199 Views
Last Modified: 2010-03-05
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
Comment
Watch Question

Epic ODBA
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Jason MintonEpic ODBA

Commented:
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
Thank you so much!
Could you break down that last segment of code for I can see what each means? Want to learn some code.

Ryan
Jason MintonEpic ODBA

Commented:
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!
Thank you very much for all of this!

Ryan
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.