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!

IF looks to recognize letters/words?

Status
Not open for further replies.

ScoobyDood

Programmer
Jun 10, 2002
15
US
Thus far I've only been able to get my IF statements to recognize numbers:

if($input==1)
{
print "Some stuff"
}
else
{
print "Some other stuff"
}

But what if I want it to recognize words?

if($input==WORDS)
{
print "Some stuff"
}
else
{
print "Some other stuff"
}

It just prints "Some stuff" no matter what I do. What's the problem? Computers - Can't live with 'em, can't live without 'em! Check this out:

 
If I understand you right and you have a specific input you want to check for you
need eq, i.e.

if($input eq 'WORDS'){....}

If on the other hand you mean when you have a nondigit character
if ($input=~/\w/){...

and if you need to check for what is between spaces
you can do
@words=split/\s+/,$input ;

== is check for NUMERIC equality

for string comparison you need eq

Good luck,
svar
 
jaaaa, don't forget to force the rigth comp
if(1*$input == digit)
if($input eq string)
in the second case, i prefer regexp

vox clamantis in deserto.
 
double equals (==) is a numeric comparison operator - if you want to work with text use 'eq' or a regex approach.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top