To initialize an array in Perl, you can use array literals or the qw() function.
In this example,
@numbers
with integer values using array literals.@numbers = (1, 2, 3, 4, 5);
print join(' ', @numbers);
1 2 3 4 5
In this example,
@fruits
with character values using the qw()
function.@fruits = qw(Apple Banana Orange);
print join(' ', @fruits);
Apple Banana Orange
In this tutorial, we learned How to Initialize an Array in Perl language with well detailed examples.