home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / WEBSERVE / SAMBAR / DATA.1 / mortgage.pl < prev    next >
Text File  |  1997-06-15  |  3KB  |  72 lines

  1. #  By Kevin Anderson
  2. #  local (*in) = @_ if @_;
  3. #  local ($i, $key, $val);
  4. #
  5. #  # Read in text
  6.     read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  7.  
  8.   @in = split(/&/,$in);
  9.  
  10.   foreach $i (0 .. $#in) {
  11.     # Convert plus's to spaces
  12.     $in[$i] =~ s/\+/ /g;
  13.  
  14.     # Split into key and value.
  15.     ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
  16.  
  17.     # Convert %XX from hex numbers to alphanumeric
  18.     $key =~ s/%(..)/pack("c",hex($1))/ge;
  19.     $val =~ s/%(..)/pack("c",hex($1))/ge;
  20.    $in{$key} .= $val;
  21. }
  22. #
  23. #
  24. $price=$in{'price'};
  25. $price =~ s/[^0-9.]//gi;
  26. if (($price eq "") || ($price == "0")) { $price=200000; }
  27. $interest=$in{'interest'};
  28. $interest =~ s/[^0-9.]//gi;
  29. if (($interest eq "") || ($interest == "0")) { $interest="8.125"; }
  30. $years=$in{'years'};
  31. $years =~ s/[^0-9.]//gi;
  32. if (($years eq "") || ($years == "0")) { $years=30; }
  33. $xprice=$in{'xprice'};
  34. $xprice =~ s/[^0-9.]//gi;
  35. if (($xprice eq "") || ($xprice == "0")) { $xprice=200000; }
  36. $xinterest=$in{'xinterest'};
  37. $xinterest =~ s/[^0-9.]//gi;
  38. if (($xinterest eq "") || ($xinterest == "0")) { $xinterest="8.125"; }
  39. $xyears=$in{'xyears'};
  40. $xyears =~ s/[^0-9.]//gi;
  41. if (($xyears eq "") || ($xyears == "0")) { $xyears=30; }
  42.  
  43. $balance=$price;
  44. $monthly=($price*$interest/100/12)/(1-(1/(1+($interest/100/12))**($years*12)));
  45. $total=$monthly*$years*12-$price;
  46. $xbalance=$xprice;
  47. $xmonthly=($xprice*$xinterest/100/12)/(1-(1/(1+($xinterest/100/12))**($xyears*12
  48. )));
  49. $xtotal=$xmonthly*$xyears*12-$xprice;  
  50. print "<html><title>Compare Monthly Payments</title>";
  51. print "<body bgcolor=\"\#FFFFFF\" text=\"\#000000\"><center>";
  52. print "<font size=+1><b>Compare Monthly Payments</b></font>";
  53. print "<FORM METHOD=\"POST\" ACTION=\"/cgi-bin/mortgage.pl\">"; 
  54. print "<table border=1 cellpadding=3><tr><td><td>Mortgage 1<td>Mortgage
  55. 2";
  56. print "<tr><td>Purchase Price";
  57. print "<td><input name=\"price\" value=\"$price\">";
  58. print "<td><input name=\"xprice\" value=\"$xprice\">";
  59. print "<tr><td>Interest Rate (eg., 8.125)";
  60. print "<td><input name=\"interest\" value=\"$interest\">";
  61. print "<td><input name=\"xinterest\" value=\"$xinterest\">";
  62. print "<tr><td>Number of Years (1-30)";
  63. print "<td><input name=\"years\" value=\"$years\">";
  64. print "<td><input name=\"xyears\" value=\"$xyears\">";
  65. printf ("<tr><td>Amount per
  66. payment<td>\$%.2f<td>\$%.2f",$monthly,$xmonthly);
  67. printf ("<tr><td>Total Interest
  68. Paid<td>\$%.2f<td>\$%.2f",$total,$xtotal);
  69. print "</table><p>";
  70. print "<input type=submit value=Calculate Mortgage>";
  71. print "</body></html>";
  72.