Perl Program Control
Provides information about Perl statements which are used for program control including the if statement, for statement, while statement, and others.
If Statements
The if statement uses the following comparisons:
| Symbol | Meaning |
| == | Equals |
| != | Not equal to |
| < | Less than |
| > | Greater than |
| <= | Less than or equal |
| >= | Greater than or equal |
An example:
if ($thisnum == 4)
{
print $msg1, "\n";
}
For Statements
The following statement counts from 1 to 5 print the results on a new line for each loop.
for ($count = 1; $count < 5; $count++)
{
print $count, "\n";
}
While Statements
$count = 0;
while ($count < 7 )
{
print $count, "\n";
$count++;
}
Foreach statements
This statement is used to operate on arrays as in the following example.
|