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

'Or' and 'And' if statements in Perl

Status
Not open for further replies.

Meatsim

Programmer
Oct 9, 2001
13
US
Hello again, I was wondering if there's any special syntax that you need to use to create 'or' and 'and' if statements, like this 'and' statement in C:

Code:
if ((a==6) && (b==6)) { printf("All you can think of is six."); }

I can't seem to get if statements like these to work in perl. Any help would be appriciated.

Thanks!
-Meatsim
 
The reason is that variables in Perl need to be written as $a and $b. The following will work:

if (($a==6) && ($b==6)) { printf("All you can think of is six."); }
 
That looks like the correct syntax to me, except for the print part, that should be:
Code:
if ((a==6) && (b==6)) { print "All you can think of is six."; }
The command you probably want to use is print, not printf. When you use printf it takes the first argument (in this case the string) and interprets it as the printf format string. That might be what's causing your problem. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top