Variable names

Variable names in Perl may contain alphanumeric characters in upper or lower case, and underscores. A variable name may not start with a number, though - that means something special, which we'll encounter later. Likewise, variables that start with anything non-alphanumeric are also special, and we'll discuss that later, too.

It's standard Perl style to name variables in lower case, with underscores separating words in the name. For instance, employee_number. Upper case is usually used for constants, for instance LIGHT_SPEED or PI. Following these conventions will help make your Perl more maintainable and more easily understood by others.

Lastly, variable names all start with a punctuation sign depending on what sort of variable they are:

Table 4-1. Variable punctuation

Variable typeStarts withPronounced
Scalar$dollar
Array@at
Hash%Percent

(Don't worry if those variable type names don't mean anything to you. We're about to cover it.)