In Perl, you declare an array using the my
keyword and assigning values.
In this example,
@numbers
and initialize it with some values.my @numbers = (1, 2, 3, 4, 5);
print join(' ', @numbers);
1 2 3 4 5
In this example,
@fruits
using the qw()
function and initialize it with some strings.my @fruits = qw(Apple Banana Orange);
print join(' ', @fruits);
Apple Banana Orange
In this tutorial, we learned How to Declare an Array in Perl language with well detailed examples.