Conditionals
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

Conditionals

To do comparisons on different values, perl provides two sets of conditionals - one for numbers and one for strings.
ComparisonStringsNumbers
Equality eq ==
Inequality ne !=
Greater than gt >
Greater than or equal to ge >=
Less than lt <
Less than or equal to le <=
Comparison
returns -1,0,1
cmp <=>

It's important to use the right conditional - there are no "syntax" errors, so if you use a variable in the wrong context, there could be unexpected results.

You can build up conditionals using && (AND) and || (OR) operations.

Truth is a very flexible value in perl:

 
  ####  Some examples of truth: 
	1;		# traditionally 
	("a","b");	# the list has elements 
	" ";		# whitespace is true 
	"hello";	# strings are true 
	"00"		# a string 
  ####  Expressions that evaluate to false 
	0;		# traditionally 
	();		# the empty list 
	"";		# the null string 
	"0";		# The one string of non-zero length that is false. 

left up right comment



NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

johnsonb@ncsa.uiuc.edu

Last modified: June 19, 1997



Retrieved by Memoweb from http://www.ncsa.uiuc.edu/General/Training/PerlIntro/cond.html at 08/02/99