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

Recommended Answers

All 3 Replies

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.

I made the changes and it still comes back with the error. URGH!

Thanks for your help though!

print the values of $type and $temp to the screen and see if they are correct. Thats the only thing that would cause the script to fall through to the "else error" condition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.