Perl scalars, lists, and hashes
Basic Types
The basic data types known to Perl are scalars, lists, and hashes.
Scalar | $foo | Simple variables that can be a number, a string, or a reference. A scalar is a “thingy.” |
List | @foo | An ordered array of scalars accessed using a numeric subscript. $foo[0] |
Hash | %foo | An unordered set of key/value pairs accessed using the keys as subscripts. $foo{key} |
Perl uses an internal type called a typeglob to hold an entire symbol table entry. The effect is that scalars, lists, hashes, and filehandles occupy separate namespaces (i.e., $foo[0] is not part of $foo or of %foo). The prefix of a typeglob is *, to indicate “all types.” Typeglobs are used in Perl programs to pass data types by reference.
You will find references to literals and variables in the documentation. Literals are symbols that give an actual value, rather than represent possible values, as do variables. For example in $foo = 1, $foo is a scalar variable and 1 is an integer literal.
Variables have a value of undef before they are defined (assigned). The upshot is that accessing values of a previously undefined variable will not (necessarily) raise an
exception.