Questions And Answers

More Tutorials

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


In this page (written and validated by ) you learned about Perl scalars, lists, and hashes . What's Next? If you are interested in completing Perl tutorial, your next topic will be learning about: Perl Variable Contexts.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.