Writing Perl Statements

Every part of a Perl script (except comments) consists of a statement. Statements:

Perl gives you the freedom to write how you want. However, a good coding style can help people who work on your code (including you) figure out what they need to change.

Coding Statements in Style

In Perl, many people find it easy to write cryptic statements that appear to accomplish a lot. However, cryptic statements typically make it a nightmare for someone who needs to change the code. Therefore, it makes sense to review and practice some basic coding styles, which follow:

By following these coding guidelines, you should save your time and the time of others. Note that the examples in this tutorial do not adhere strictly to these guidelines because they serve a special purpose.

Statement Examples

These examples may seem simple, but they do illustrate the points of this section. The example below shows the call to the Perl "Print()" function:
# Example of a statement using the Perl Print() function.
print("Hello, world!");
This next example shows the assignment of the value "1" (a RValue) to the variable $index (a LValue):
# Example of a statement using a LValue and RValue.
$index = 1;
Finally, we show you an example of a statement using the Perl "if" program flow control statement:
# Example of a statement using program flow control.
if ($index eq 1) {
    print "Index equals 1!\n";
}
Now that you know how to write comments and statements, you should take the next big step of running a Perl program.