| | |
Need help with Script
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
Hello:
I am a newbie and need help with a celsius to fahrenheit script. If anyone can help, it would be greatly appreciated. Right now, it comes back with the error
Here is my HTML code:
<!xxxx.html>
<HTML>
<HEAD><TITLE>XXXXX Temperature Conversion</TITLE></HEAD>
<BODY>
<H3>Use this form to convert a temperature.</H3><BR />
<FORM ACTION="http://cgi-bin/xxxx.cgi" method=POST>
<P><input type="text" name="Temp" size="5"><BR/><BR/>
<DIV>
<SELECT NAME="Type"><OPTION VALUE="c_fah">Convert from Celsius to Fahrenheit<BR/>
<OPTION VALUE="f_cel">Convert from Fahrenheit to Celsius<BR/>
<INPUT TYPE="submit" VALUE="Submit">
</DIV>
</FORM>
</BODY>
</HTML>
Here is my script:
#!/usr/bin/perl
#xxxx.cgi --calculates temperature conversion on a dynamic web page
print "Content-type: text/html\n\n";
use CGI qw(:standard -debug);
use strict;
#declare variables
my ($temp, $f_temp, $c_temp, $type);
$temp = param('Temp');
$type = param('Type');
calc_temp();
exit;
#*****user-defined functions*****
sub calc_temp {
if ($type eq "c_fah") {
my $f_temp = $temp * 9 / 5 + 32;
print "$temp degree Celsius is $f_temp degree Fahrenheit.\n";
}
elsif ($type eq "f_cel") {
my $c_temp = ($temp - 32) * 5 / 9;
print "$temp degree Fahrenheit is $c_temp degree Celsius.\n";
}
else {
print "Error\n";
}
} #end calc_temp
I am a newbie and need help with a celsius to fahrenheit script. If anyone can help, it would be greatly appreciated. Right now, it comes back with the error
Here is my HTML code:
<!xxxx.html>
<HTML>
<HEAD><TITLE>XXXXX Temperature Conversion</TITLE></HEAD>
<BODY>
<H3>Use this form to convert a temperature.</H3><BR />
<FORM ACTION="http://cgi-bin/xxxx.cgi" method=POST>
<P><input type="text" name="Temp" size="5"><BR/><BR/>
<DIV>
<SELECT NAME="Type"><OPTION VALUE="c_fah">Convert from Celsius to Fahrenheit<BR/>
<OPTION VALUE="f_cel">Convert from Fahrenheit to Celsius<BR/>
<INPUT TYPE="submit" VALUE="Submit">
</DIV>
</FORM>
</BODY>
</HTML>
Here is my script:
#!/usr/bin/perl
#xxxx.cgi --calculates temperature conversion on a dynamic web page
print "Content-type: text/html\n\n";
use CGI qw(:standard -debug);
use strict;
#declare variables
my ($temp, $f_temp, $c_temp, $type);
$temp = param('Temp');
$type = param('Type');
calc_temp();
exit;
#*****user-defined functions*****
sub calc_temp {
if ($type eq "c_fah") {
my $f_temp = $temp * 9 / 5 + 32;
print "$temp degree Celsius is $f_temp degree Fahrenheit.\n";
}
elsif ($type eq "f_cel") {
my $c_temp = ($temp - 32) * 5 / 9;
print "$temp degree Fahrenheit is $c_temp degree Celsius.\n";
}
else {
print "Error\n";
}
} #end calc_temp
This is wrong:
<FORM ACTION="http://cgi-bin/xxxx.cgi" method=POST>
probably should be:
<FORM ACTION="cgi-bin/xxxx.cgi" method=POST>
You also need a </select> tag:
<SELECT NAME="Type">
<OPTION VALUE="c_fah">Convert from Celsius to Fahrenheit<BR/>
<OPTION VALUE="f_cel">Convert from Fahrenheit to Celsius<BR/>
</SELECT>
besides that it looks like the script should work.
<FORM ACTION="http://cgi-bin/xxxx.cgi" method=POST>
probably should be:
<FORM ACTION="cgi-bin/xxxx.cgi" method=POST>
You also need a </select> tag:
<SELECT NAME="Type">
<OPTION VALUE="c_fah">Convert from Celsius to Fahrenheit<BR/>
<OPTION VALUE="f_cel">Convert from Fahrenheit to Celsius<BR/>
</SELECT>
besides that it looks like the script should work.
![]() |
Similar Threads
- Clean Previous Next Script for MySQL results (PHP)
- The name for the Resize Button to ad to Script (HTML and CSS)
- Random Programming Script (Computer Science)
- Importing SQL Script File - Urgent !! (Database Design)
- Script problems with IE (Web Browsers)
- Help with shell script to auto gzip a .sql dump after backup (Shell Scripting)
- Adding mutiple PC's to an OU via script? (Windows NT / 2000 / XP)
- Table of Contents Script (Java)
- ASP slow-down server script (ASP)
Other Threads in the Perl Forum
- Previous Thread: Day out of range
- Next Thread: How to install PERL
| Thread Tools | Search this Thread |
Tag cloud for Perl





