Arrays
Explore Perl arrays and understand how to store, access, and modify data using indexed and negative positions. Learn array initialization, assignment, dynamic resizing, and clearing techniques to manage data collections effectively in Perl programming.
Perl’s array data type is a language-supported aggregate that stores zero or more scalars. We can access individual members of the array by integer indexes, and we can add or remove elements at will. Arrays grow or shrink as we manipulate them.
The @ sigil denotes an array. To declare an array, we write this:
my @items;
Array elements
We use the scalar sigil to access an individual element of an array. $cats[0] refers
unambiguously to the @cats array, because postfix square
brackets [] always mean indexed access to an array.
The first element of an array is at the zeroth index:
# @cats contains a list of Cat ...