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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returns wrong results. why 1

Status
Not open for further replies.

lordhuh

Programmer
Apr 25, 2000
96
US
here is the entire code.&nbsp;&nbsp;this procese an input for &quot;operation&quot;.&nbsp;&nbsp;if it is run then it returns run.&nbsp;&nbsp;if it does not it returns not.&nbsp;&nbsp;no matter what i pass to it it returns run.&nbsp;&nbsp;i am new to perl and have no idea.<br><br><br>#!/perl/bin/<br># get form input, split each form field into @pairs array<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});<br>@pairs = split(/&/, $buffer);<br># clean up each array element<br>foreach $pair (@pairs) {<br>&nbsp;&nbsp;&nbsp;($name, $value) = split(/=/, $pair);<br>&nbsp;&nbsp;&nbsp;$value =~ tr/+/ /;<br>&nbsp;&nbsp;&nbsp;$value =~&nbsp;&nbsp;&nbsp;&nbsp;s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;,hex($1))/eg;<br>&nbsp;&nbsp;&nbsp;$value =~ s/\n/ /g; # replace newlines with spaces<br>&nbsp;&nbsp;&nbsp;$value =~ s/\r//g; # remove hard returns<br>&nbsp;&nbsp;&nbsp;$value =~ s/\cM//g; # delete ^M's<br>&nbsp;&nbsp;&nbsp;$FORM{$name} = $value;<br>}<br><br>if ($FORM{'operation'}=run){<br>print &lt;&lt;END;<br>Content-Type: text/html\n\n<br>&lt;html&gt;<br>&lt;center&gt;&lt;h2&gt;Results&lt;/h2&gt;&lt;/center&gt;&lt;p&gt;<br>run<br>&lt;/body&gt;<br>&lt;/html&gt;<br>END<br>}<br>else{<br>print &lt;&lt;END;<br>Content-Type: text/html\n\n<br>&lt;html&gt;<br>&lt;center&gt;&lt;h2&gt;Results&lt;/h2&gt;&lt;/center&gt;&lt;p&gt;<br>else<br>&lt;/body&gt;<br>&lt;/html&gt;<br>END<br>}
 
The line <FONT FACE=monospace><b>if ($FORM{'operation'}=run){</font></b> looks a little suspect. Easy mistake to make.<br><br>When you're comparing two numbers - use <FONT FACE=monospace><b>==</font></b><br>When you're comparing two strings - use <FONT FACE=monospace><b>eq</font></b><br><br>Don't use <FONT FACE=monospace><b>=</font></b> as that is the assignment operator, use that when you want to set the value of something, like this:<br><br><FONT FACE=monospace><b><br>$x=&quot;hello&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# $x now equals &quot;hello&quot;<br>if($x eq &quot;goodbye&quot;){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# this will fail<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;whoops!!\n&quot;;<br>} else {<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;it worked!!\n&quot;;&nbsp;&nbsp;&nbsp;&nbsp;# this should print<br>}<br></font></b><br><br>Oh - and don't forget to put strings in quotes.<br><br> <p>Mike<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
thanks im used to visual basic which only uses one = and the quotes i just plain forgot. <p>Karl Pietri<br><a href=mailto:lordhuh.pota.to>lordhuh.pota.to</a><br><a href= > </a><br>
 
everyone does <p>Mike<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>Please don't send me email questions without posting them as well. Post the question and send me a note saying "Have a look at so-and-so would you?" - that's fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top