Perl Programming Language

Variables

By

First published on September 9, 2019. Last updated on February 16, 2020.


The most simple type of variable in Perl are single value variables called scalers. They are used for numbers or single strings of text. Their names should begin with “$”.

In Perl, you should declare your variables the first time you use them. For example:

my $year = 2019;

If you are assigning a string (e.g. text), the string must be placed in quotes:

my $city = "Nairobi";

Arrays are used for variables that contain multiple values. In Perl, arrays should begin with “@”, for example:

my @fruits = ("apple", "banana", "orange");

Arrays are referenced by item number (starting with 0):

print @fruits[1];

will display:

banana

 


COURSE


Content is copyright the author. Layout is copyright Mark Ciotola. See Corsbook.com for further notices.