Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 2.4 Scalar OperatorsChapter 2
Scalar Data
Next: 2.6 Scalar Operators and Functions
 

2.5 Scalar Variables

A variable is a name for a container that holds one or more values. The name of the variable is constant throughout the program, but the value or values contained in that variable typically change over and over again throughout the execution of the program.

A scalar variable holds a single scalar value (representing a number, a string, or a reference). Scalar variable names begin with a dollar sign followed by a letter, and then possibly more letters, or digits, or underscores.[9] Upper- and lowercase letters are distinct: the variable $A is a different variable from $a. And all of the letters, digits, and underscores are significant, so:

[9] Limited to 255 characters, however. We hope that suffices.

$a_very_long_variable_that_ends_in_1

is different from:

$a_very_long_variable_that_ends_in_2

You should generally select variable names that mean something regarding the value of the variable. For example, $xyz123 is probably not very descriptive, but $line_length is.


Previous: 2.4 Scalar OperatorsLearning Perl on Win32 SystemsNext: 2.6 Scalar Operators and Functions
2.4 Scalar OperatorsBook Index2.6 Scalar Operators and Functions