Accessing Elements: Populating an array and printing its values
@names=('John', 'Joe', 'Jake');
print @names, "\n";
print "Hi $names[0], $names[1], and $names[2]!\n";
$number=@names;
print "$number elements in the \@names array.\n";
print "The last element is $names[$number - 1].\n";
print "The last element is $names[$#names].\n";
@fruit = qw(a b c d);
print "The first element of the \@fruit array is $fruit[0];the second element is $fruit[1].\n";
print "@fruit[-1, -3]\n";
Related examples in the same category