This section describes how a scalar variable can be assigned with a scalar value. An unassigned scalar variable contains the (undef) value. The undef() function removes the assigned value from a scalar variable.
Scalar variables can be used in a Perl script under these rules:
A scalar variable should be assigned with a scalar value constructor using an assignment operation.
For example, $price = 19.99.
A scalar variable without any scalar value assigned is an undefined variable and contains a special value called, undef.
The assigned value can be removed from a scalar variable using the undef() function.
A scalar variable can be used in a numeric operation, where the value contained in the scalar variable will be interpreted as a number.
A scalar variable can be used in a string operation, where the value contained in the scalar variable will be interpreted as a string.
A scalar variable can be used in a Boolean operation, where the value contained in the scalar variable will be interpreted as TRUE or FALSE.
See the previous section for scalar value interpretation rules.
Here are some examples of scalar variable assignment operations with scalar value constructors: