Hi, guys. In this tutorial, we will learn the data types in Perl language. Basically, there are three data types: scalars, arrays of scalars and hashes of scalars. There is a big different between Perl language and others language (e.g. C language, Java language, ...). Since Perl language is a loosely typed language, therefore it doesn't need to define the type of data (e.g. integer, string, character, ...) when using in the program, while others do so before using it.
We will store these data type as variable before we use it. What is variable? Variable is the reserved memory locations to store values. These values can be integers, strings or decimals. The Perl interpreter will allocates the memory and make decisions what will be stored in the reserved memory.
In this tutorial, we will learn the first data type which is scalar.
Scalars
Variable Scalars
A scalar is a single unit data. This data can be an integer number, double point, floating point, a string or a character. Or in other word, it can be anything, but only can store single thing. This scalar variable will be come before by a dollar sign ($). Below is the example using scalar variable.
#!/usr/bin/perl
$name = "Man Yeap"; # Store as String
$age = 24; # Store as integer
$gender = 'M'; # Store as character
print "Name : $name\n";
print "Age : $age\n";
print "Gender : $gender\n";