Perl Array



Arrays are lists of scalars. Perl Array names begin with @. Perl Arrays are defined by listing the content in parentheses, separated by commas:

@newarray = (1, 2, 3, 4, 5, 6);
@montharray = ("Jan", "Feb", "March");

The contents of an array starts from index 0. To fetch an elements of the array, you use a $ sign followed by the index position of the element as follows:

    @montharray = ("Jan", "Feb", "March");
    print $montharray[0];   # This prints "Jan".
    $montharray[2] = "August";  # We just renamed March to August.

implicitly creates @winter_months.

The length of the array can be find out by using the value $#array_name. This is one less than the number of elements in the array.

     @montharray = ("Jan", "Feb", "March");
    print $#montharray;         # This prints 3.
    $#montharray = 0;           # Now @montharray only contains "Jan".

In the 3rd line above, we resized the array size to 1.

You can refer this link for more detail: Perl Arrays