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

Can Scalers in IF statements not represent words?

Status
Not open for further replies.

ScoobyDood

Programmer
Jun 10, 2002
15
US
Ok, I was working in this script (It's a logic riddle by the way) that looked something like this: (In part)

#Script starts here

$food=cgiobject->param("food");

if ($food==Pizza)
print {"No, the answer was Cheese Stix!";}
elsif ($food==Cheese Stix)
print ("That is correct!";}
else
print {"That was not a choice!";}

#Script ends here

Well, it didn't work! No matter what you typed in, it said "No, the answer was Cheese Stix!". So then I did this, and you had to type in either choice 1 or choice 2:

#Script starts here

$food=cgiobject->param("food");

if ($food==1)
print {"No, the answer was Cheese Stix!";}
elsif ($food==2)
print ("That is correct!";}
else
print {"That was not a choice!";}

#Script ends here

And it worked! It gets the job done, but it's just not the same. So what's the deal? Can IF statements only represent numbers? If so, what kind of script can I use to meet my needs? Thanks. Computers - Can't live with 'em, can't live without 'em! Check this out:

 
replace the == by eq ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
and put single or double quotes around Pizza and Cheez Stix.

jaa
 
oh yeah, and

use warnings;

It would have pointed you in the right direction.

jaa
 
so using justice41 tip and mine i should be some thing like

#!perl -W
use strict; # learn good habbits
use warnings; # justice41 tip
use diagnostics; # more info on error

my $food = cgiobject->param("food");

if ($food eq "Pizza") {
print "No, the answer was Cheese Stix!";
} elsif ($food eq "Cheese Stix") {
print "That is correct!";
} else {
print "That was not a choice!";
}

# if/elsif/else are used like this
# if (conditions) { statements;} else { statements;}

# print does not use { } just do
# print "stuff";

# hope this helps a little
exit;
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top