jasper23
Programmer
- Oct 26, 2007
- 1
Hello,
I am developing a cgi-perl script that takes some value from a html form as input and stores them in a data file. I have a program called "irr" in my server, it is executed just by typing irr at the shell prompt. Upon execution the program first displays a line describing the types of input required and waits for the input in the next line.I intend to pass the inputs from the values stored in the data file by the script. The following is the code that i came up with:
#!/usr/bin/perl -w
use warnings;
use CGI qwall);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qwflock);
use strict;
my $dataFile="data.txt";
print header(-type=>'text/html');
print start_html("Internal Rate of Return Calculator");
my $value = `date`;
print $value,"<br\>";
my $irr;
if(!param)
{
form();
print end_html();
}
else
{
store();
result();
print end_html();
}
#-----------------------------------
sub form(){
print << "HERE";
<form id="form" action="" method="POST"/>
<h1> Welcome to IRR Calculator </h1>
<p>Net-Present-Value: <input name="value" type="text"/></p>
<p>Amortization-In-Years: <input name="years" type="text"/></p>
<p>Monthly-Cashflow: <input name="monthly" type = "text"/></p>
<p><input name="submit" type="submit" value="submit"/></p>
</form>
HERE
}
#------------------------------------
sub store(){
my $value = param('value');
my $years = param('years');
my $monthly = param('monthly');
open (DH, ">$dataFile") || die "Coudn't open the data file: $!";
print DH $value, " ", $years, " ", $monthly;
close(DH);
}
#-------------------------------------
sub result(){
my $irr = `irr<data.txt`;
print $irr;
}
----------------------------------------------------------------
Unfortunately the result is never displayed on the browser. I have tried using the command : `irr<data.txt | cat` but that doesn't work either. Where am I doing wrong? A little help would be greatly appreciated. Thank you.
I am developing a cgi-perl script that takes some value from a html form as input and stores them in a data file. I have a program called "irr" in my server, it is executed just by typing irr at the shell prompt. Upon execution the program first displays a line describing the types of input required and waits for the input in the next line.I intend to pass the inputs from the values stored in the data file by the script. The following is the code that i came up with:
#!/usr/bin/perl -w
use warnings;
use CGI qwall);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qwflock);
use strict;
my $dataFile="data.txt";
print header(-type=>'text/html');
print start_html("Internal Rate of Return Calculator");
my $value = `date`;
print $value,"<br\>";
my $irr;
if(!param)
{
form();
print end_html();
}
else
{
store();
result();
print end_html();
}
#-----------------------------------
sub form(){
print << "HERE";
<form id="form" action="" method="POST"/>
<h1> Welcome to IRR Calculator </h1>
<p>Net-Present-Value: <input name="value" type="text"/></p>
<p>Amortization-In-Years: <input name="years" type="text"/></p>
<p>Monthly-Cashflow: <input name="monthly" type = "text"/></p>
<p><input name="submit" type="submit" value="submit"/></p>
</form>
HERE
}
#------------------------------------
sub store(){
my $value = param('value');
my $years = param('years');
my $monthly = param('monthly');
open (DH, ">$dataFile") || die "Coudn't open the data file: $!";
print DH $value, " ", $years, " ", $monthly;
close(DH);
}
#-------------------------------------
sub result(){
my $irr = `irr<data.txt`;
print $irr;
}
----------------------------------------------------------------
Unfortunately the result is never displayed on the browser. I have tried using the command : `irr<data.txt | cat` but that doesn't work either. Where am I doing wrong? A little help would be greatly appreciated. Thank you.