Need help with Script

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 5
Reputation: reno02 is an unknown quantity at this point 
Solved Threads: 0
reno02 reno02 is offline Offline
Newbie Poster

Need help with Script

 
0
  #1
Oct 20th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Need help with Script

 
0
  #2
Oct 20th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 5
Reputation: reno02 is an unknown quantity at this point 
Solved Threads: 0
reno02 reno02 is offline Offline
Newbie Poster

Re: Need help with Script

 
0
  #3
Oct 21st, 2008
I made the changes and it still comes back with the error. URGH!

Thanks for your help though!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Need help with Script

 
0
  #4
Oct 21st, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC