Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi/perl variable and operaator question (newbie) 1

Status
Not open for further replies.

craazycanuck

Technical User
Apr 28, 2001
7
CA
Hope someone can give me a hand.I have an html document with two inputs .I want to generate a perl script that will add 3 to the inputs then multiply the results together to reach an end result.I can get the inputs to add 3 but I can't figure out how to get the end result.Any assistance appreciated.
Ty in advance

#!/usr/bin/perl
print "Content-type: text/html\n\n";
$forminfo = <STDIN>;
@key_value_pairs = split(/&/,$forminfo);
foreach $pair (@key_value_pairs){
($key,$textA,$textB) = split(/=/,$pair);
$textA +=3;
$textB +=3;
$answer=&quot;&quot;;
$answer=$textA*$textB;
$textA=~ s/%([0-9a-fA-F][0-9a-fA-F])/pack(&quot;C&quot;, hex($1))/eg;
$textB=~ s/%([0-9a-fA-F][0-9a-fA-F])/pack(&quot;C&quot;, hex($1))/eg;
$FORM_DATA{$key} = $textA;
$FORM_DATA{$key} = $textB;
}
print &quot;Input 1= $FORM_DATA{'textA'}&quot;, &quot;\n\n&quot;;
print &quot;<br>\n&quot;;
print &quot;Input 2= $FORM_DATA{'textB'}&quot;, &quot;\n\n&quot;;
print &quot;<br>\n&quot;;
print &quot;Answer = $FORM_DATA{'answer'}&quot;, &quot;\n\n&quot;;
 
you're doing things out of order is all...[tt]

print &quot;Content-type: text/html\n\n&quot;;
$forminfo = <STDIN>;
@key_value_pairs = split(/&/,$forminfo);
foreach $pair (@key_value_pairs){
($key,$value) = split(/=/,$pair);
$value=~ s/%([0-9a-fA-F][0-9a-fA-F])/pack(&quot;C&quot;, hex($1))/eg;
$FORM_DATA{$key} = $value;
}
print &quot;Input 1= $FORM_DATA{'textA'}\n<br>\n&quot;;
print &quot;Input 2= $FORM_DATA{'textB'}\n<br>\n&quot;;
print &quot;Answer = &quot;, (($FORM_DATA{'textB'} + 3) * ($FORM_DATA{'textA'} + 3)), &quot;\n&quot;;
[/tt]

and just to make sure, the math you wanted was (A plus 3) times (B plus 3), right? &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top