Array Variable in Perl
What is an array?
Explanation
The Array is nothing but a collection of elements, grouped under a single variable name.
Syntax:
@arrayname = ("value1", value2");
Example :
#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
@colors = ();
@numbers =(1,2,3);
@name = ( "alan", "jack");
$colors [0] = red;
$colors [1] = green;
$colors [2] = blue;
print @colors;
print "<br>";
print @numbers;
print "<br>";
print @name;
Result :
redgreenblue
123
alanjack
In the above example, if the elements are strings, then it is enclosed within quotes, and each element in an array can be accessed by providing the index value which starts from 0 to one less than the total number of elements. Perl indexes array elements as scalar variable.