VOOZH about

URL: https://www.geeksforgeeks.org/perl/perl-data-types/

⇱ Perl | Data Types - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Perl | Data Types

Last Updated : 11 Jul, 2025

Data types specify the type of data that a valid Perl variable can hold. Perl is a loosely typed language. There is no need to specify a type for the data while using in the Perl program. The Perl interpreter will choose the type based on the context of the data itself. 

There are 3 data types in Perl as follows: 

  1. Scalars
  2. Arrays
  3. Hashes(Associative Arrays)

1. Scalars:

It is a single unit of data that can be an integer number, floating-point, a character, a string, a paragraph, or an entire web page. To know more about scalars please refer to Scalars in Perl

Example:

Output: 

Age = 1
Name = ABC
Salary = 21.5

Scalar Operations: There are many operations that can be performed on the scalar data types like addition, subtraction, multiplication, etc.

Example:

Output: 

str = GFG is the best
num = 1
mul = 36
mix = GFG is the best1

2. Arrays:

An array is a variable that stores the value of the same data type in the form of a list. To declare an array in Perl, we use '@' sign in front of the variable name. 

@age=(10, 20, 30)

It will create an array of integers that contains the values 10, 20, and 30. To access a single element of an array, we use the '$' sign. 

$age[0]

It will produce an output of 10. To know more about arrays please refer to Arrays in Perl

Example:

Output: 

$ages[0] = 33
$ages[1] = 31
$ages[2] = 27
$names[0] = Geeks
$names[1] = for
$names[2] = Geeks

3. Hashes(Associative Arrays):

It is a set of key-value pair. It is also termed the Associative Arrays. To declare a hash in Perl, we use the '%' sign. To access the particular value, we use the '$' symbol which is followed by the key in braces.

Example:

Output: 

$data{'GFG'} = 7
$data{'for'} = 4
$data{'Geeks'} = 11
Comment
Article Tags:

Explore