Scalars
Learn about scalars and their types in Perl.
Scalars
Perl’s fundamental data type is the scalar: a single, discrete value. That value can be a string, an integer, a floating-point value, a filehandle, or a reference, but it’s always a single value. Scalars may be lexical, package, or global variables. We may declare only lexical or package variables. The names of scalar variables must conform to standard variable-naming guidelines. Scalar variables always use the leading dollar sign $
.
Note: Scalar values and scalar context have a deep connection; assigning to a scalar imposes scalar context. Using the scalar sigil with an aggregate variable accesses a single element of the hash or array in the scalar context.
Scalars and types
A scalar variable can contain any type of scalar value without special conversions, coercions, or casts. The type of value stored in a scalar variable, once assigned, can change arbitrarily:
Get hands-on with 1400+ tech skills courses.