# Data types Perl has three fundamental data types — **scalars**, **arrays**, and **hashes** — plus a small number of supporting kinds (references, typeglobs, code) that are technically scalars but behave differently enough to deserve their own treatment. Every value the language manipulates is one of these. This reference is split into one page per topic. Topics that share context (numeric vs string conversion, references vs typeglobs, context vs interpolation) live in the same page; topics that don’t share context get their own page. ## Choose a topic * [Scalars](perldata/scalars.md) * [Arrays](perldata/arrays.md) * [Hashes](perldata/hashes.md) * [Context](perldata/context.md) * [Numbers and strings](perldata/numeric-strings.md) * [References](perldata/references.md) * [Typeglobs](perldata/typeglobs.md) * [Interpolation](perldata/interpolation.md) - [Scalars](perldata/scalars.md) — `$x`. Numbers, strings, references; `undef`; truth and definedness; the dual numeric/ string nature of scalars. - [Arrays](perldata/arrays.md) — `@arr`. Element access, `$#arr`, negative indices, slices, list assignment, the `@arr` / `$arr[i]` / `@arr[i,j]` sigil rule. - [Hashes](perldata/hashes.md) — `%h`. Key-value pairs, the four flavours of subscript, `keys`/`values`/`each`, key ordering, hash slices and key/value slices. - [Context](perldata/context.md) — list, scalar, void, boolean. How each operator and assignment imposes context, what `wantarray` reports, the `scalar()` operator, and the recurring traps with `,` versus list construction. - [Numbers and strings](perldata/numeric-strings.md) — automatic conversion both ways, integer vs float, `Inf` and `NaN`, numeric literal forms, «0 but true», `dualvar`, locale and precision pitfalls. - [References](perldata/references.md) — `\X`, the seven things you can reference, the four ways to deref, autovivification, weak references, circular structures, `ref` and `Scalar::Util`. - [Typeglobs](perldata/typeglobs.md) — `*name`. The symbol-table entry, aliasing, `*foo{THING}`, when modern Perl still needs them and when references are the right answer instead. - [Interpolation](perldata/interpolation.md) — what double-quoted strings, here-docs, and regex patterns interpolate; the `${name}` braces; the `@{[ expr ]}` and `${\ expr }` baroque constructs; ambiguities with `[` and `{` after a sigil. ## Cross-cutting concepts A handful of ideas appear on every page below. Read these once and the rest will feel familiar: - **Sigils mark the *result*, not the container.** `@arr[1, 3]` is not «two arrays»; the `@` says «the result is a list». The variable named `arr` is the same in `@arr`, `$arr[0]`, `@arr[0..3]`, and `%arr[0..3]`. - **Context coerces.** A scalar evaluated in list context becomes a one-element list; a list evaluated in scalar context yields its **last** element (comma operator), but an *array* in scalar context yields its **length**. The two cases are not the same; see [context](perldata/context.md). - **References are scalars.** A reference to anything fits in a scalar variable, which is what makes nested data structures possible. The deref syntax (`@$ref`, `$ref->[0]`, `${$ref}{key}`) is the inverse of `\`. - **`undef` is a value, not the absence of one.** A scalar can hold the value `undef`; testing `defined $x` is how you ask. An array can have `undef` elements without being empty. - **Strings and numbers convert silently.** `"42" + 1` is `43`, `42 . "x"` is `"42x"`. The conversion is always defined; see [numbers and strings](perldata/numeric-strings.md) for what counts as «looks like a number» and where the corners are. ## See also - [`perlop`](perlop.md) — the operators that read and produce these values (arithmetic, comparison, subscript, range, arrow, assignment). - [`perlvar`](perlvar.md) — the special variables Perl populates with state from the last operation, including `$_`, `@_`, the match variables, and the I/O-shaping `$/`, `$\`, `$,`, `$"`. - [`perlfunc`](perlfunc.md) — the built-in functions that operate on these types: `ref`, `scalar`, `wantarray`, `defined`, `keys`, `values`, `each`, `exists`, `delete`, `bless`. - [References tutorial](../../tutorial/reference/index.md) — step-by-step introduction to the reference forms covered tersely in [references](perldata/references.md).