×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

returns wrong results. why

returns wrong results. why

returns wrong results. why

(OP)
here is the entire code.  this procese an input for "operation".  if it is run then it returns run.  if it does not it returns not.  no matter what i pass to it it returns run.  i am new to perl and have no idea.


#!/perl/bin/
# get form input, split each form field into @pairs array
                          read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
# clean up each array element
foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~    s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
   $value =~ s/\n/ /g; # replace newlines with spaces
   $value =~ s/\r//g; # remove hard returns
   $value =~ s/\cM//g; # delete ^M's
   $FORM{$name} = $value;
}

if ($FORM{'operation'}=run){
print <<END;
Content-Type: text/html\n\n
<html>
<center><h2>Results</h2></center><p>
run
</body>
</html>
END
}
else{
print <<END;
Content-Type: text/html\n\n
<html>
<center><h2>Results</h2></center><p>
else
</body>
</html>
END
}

RE: returns wrong results. why

The line if ($FORM{'operation'}=run){ looks a little suspect. Easy mistake to make.

When you're comparing two numbers - use ==
When you're comparing two strings - use eq

Don't use = as that is the assignment operator, use that when you want to set the value of something, like this:


$x="hello";                    # $x now equals "hello"
if($x eq "goodbye"){            # this will fail
    print "whoops!!\n";
} else {
    print "it worked!!\n";    # this should print
}


Oh - and don't forget to put strings in quotes.

Mike
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

RE: returns wrong results. why

(OP)
thanks im used to visual basic which only uses one = and the quotes i just plain forgot.

Karl Pietri
lordhuh.pota.to

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close