Data Types and Variables
Perl has three basic data types: scalars, arrays, and hashes.
Scalars are essentially simple variables.
They are preceded by a
dollar sign ($).
A scalar is either a number, a string, or a reference.
(A reference is a scalar that points to another piece of data. References are
discussed later in this chapter.)
If you provide a string where a number is expected or vice versa, Perl
automatically converts the operand using fairly intuitive rules.
Arrays are ordered lists of scalars that you
access with a numeric subscript (subscripts start at 0).
They are preceded by an
“at” sign (@).
Hashes are unordered sets of
key/value pairs that you access using
the keys as subscripts.
They are preceded by a
percent sign (%).
Numbers
Perl stores numbers internally as either signed integers or double-precision floating-point values. Numeric literals are specified in any of the following floating-point or integer formats:
12345 # integer -54321 # negative integer 12345.67 # floating point 6.02E23 # scientific notation 0xffff # hexadecimal 0377 # octal 4_294_967_296 # underline for legibility
Since Perl uses the comma as a list separator, you cannot use a comma for
improving legibility
of a large number. To improve legibility, Perl allows you
to use an underscore character instead. The underscore only
works within literal numbers specified in your program, not in strings
functioning as numbers or in data read from somewhere else. Similarly, the
leading 0x for hex and ...