There are three types of data types in Perl.
- List or Array
- Hash or also called associative Array.
What are the Perl data types?
Perl has three types of data types.
Scalars : It stores Single units of items. Variables of these types are declared with the
$prefix. These can be single values of the string, number, floating, and references. An example is
List or Array:
It is used to store the same type of scalar type and order.
An example is
Hashes Stores keys and values without any order. An example is
Scalars in Perl
Scalar types are used to store a single unit of data.
Data can be numbers, floating values, strings, and characters.
$id = 11; # An integer assignment $name = "Eric"; # A string $marks = 45.50; # A floating point print "Age = $age\n"; print "Name = $name\n"; print "Salary = $salary\n";
Array type in Perl
The array is a collection of Scalar items with insertion order.
Arrays in Perl declared with variable name prefixed with
Here is an example
@numbers = (20, 40, 10); @words = ("one", "two", "three");
Hashs data type in Perl
Hashes are also called associate arrays in Perl.
It contains key and value pairs.
Hashes variable declared with
Data can be retrieved using $hashes.
\# Perl example on Hashes %countries = ('India', 'IND', 'United States Of America', 'USA', 'Canada', "CAN");