
| Contents |
|||||||||||||||||||||||||||||
| [an error occurred while processing this directive] |
1.2 Expressions, Statements, and Side-EffectsBefore we begin introduce more Perl code examples, we want to explain the ideas of an expression and a statement, and how each looks in Perl. Any valid "chunk" of Perl code can be considered an expression. That expression always evaluates to some value. Sometimes, the value to which expression evaluates is of interest to us, and sometimes it is not. However, we always must be aware that each expression has some "value" that is the evaluation of that expression.
Zero or more expressions to make a statement in Perl. Statements
in Perl end with a semi-colon. For example, in the Perl code we saw
before, we turned the expression,
Given that every expression, even when combined into statements,
evaluate to some value, you might be tempted to ask: What does the
expression
The side-effect of an expression is some change that occurs as a
result of that expression's evaluation. Often, a side-effect causes
some change in the state of the running program, such as changing the
value of a variable. In the expression
Let's now consider a slightly more complex statement, and look for the
the expressions and side-effect. Consider the statement,
To cause that assignment to take place, we used the larger expression,
The concepts of statements, expressions and side-effects will become more clear as we continue. When appropriate, we'll point out various expression and discuss what they evaluate to, and indicate what side-effects are of interest to us.
|