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.[30]
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:
$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.
[30] Limited to 255 characters, however. We hope that suffices.
Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.