What data types Perl has? And how can we define it?
Answer
- Scalar: This is a simple variable that stores single data items. It can be a string, number or reference.
my $number = 5;
- Arrays: This is a list of scalars.
my @numbers = (1, 2, 3, 4, 5);
# or using the `qw` keyword (quote word):
my @numbers = qw/1 2 3 4 5/;
# '/' can be another symbol, e.g qw@1 2 3 4 5@
- Hashes (or associative arrays): This is an unordered collection of key-value pairs. We can access to a hash using the keys.
my %numbers = (
First => '1',
Second => '2',
Third => '3'
);