![](/WDVL/Website/Design/images/spacer.gif) |
Equality operators
Equality operators
If you are confused about the usage of the
"if" test, it is explained in greater detail in the
"Control Structures" section later. |
- The "ne" operator asks if the value of the variable
$display_frontpage_submit_button is not equal to an
empty string. This logic takes advantage of the fact that
the HTTP protocol specifies that if a FORM submit
button is pressed, its NAME is set equal to the VALUE
specified in the HTML code. For example, the submit
button may have been coded using the following HTML:
<INPUT TYPE = "submit"
NAME = "display_frontpage_submit_button"
VALUE= "Return to the Frontpage"
>
-
Thus, if the NAME in the associative array has a
VALUE, the script knows that the client pushed the
associated button. The script determines which routines it
should execute by following the logic of these pattern
matches.
- Similarly, you can test for equality using the "eq"
operator. An example of the "eq" operator in use is
shown below:
if ($name eq "Selena")
{
print "Hi, Selena\n";
}
- When comparing numbers instead of strings however,
Perl uses a second set of operators. For example, to test
for equality, you use the double equal (==) operator as
follows:
if ($number == 11)
{
print "You typed in 11\n";
}
Warning: Never use the single equal sign (=)
for comparison. Perl interprets the equal sign in
terms of assignment rather than comparison. Thus
the line:
$number = 11;
actually assigns the value of eleven to $number rather
than comparing $number to eleven. |
- There are many other types of comparison operators, but
they are better researched in more comprehensive texts.
However, we do include several important ones in the
following table
Numeric Op. |
String Op |
Description |
== |
eq |
Equal |
!= |
ne |
Not equal |
< |
lt |
Less than |
> |
gt |
Greater than |
<= |
le |
Less than or equal to |
>= |
ge |
Greater than or equal to |
Additional Resources:
Manipulating Strings in Perl
Table of Contents
Regular Expressions
| ![](/WDVL/Website/Design/images/spacer.gif) |
|