Arrays in Perl
#!perl
@array = ( "A", "B", "C", "D" );
print "The array contains: @array\n";
print "Printing array outside of quotes: ", @array, "\n\n";
print "Third element: $array[ 2 ]\n";
$number = 3;
print "Fourth element: $array[ $number ]\n\n";
@array2 = ( A..Z );
print "The range operator is used to create a list of\n";
print "all letters from capital A to Z:\n";
print "@array2 \n\n";
$array3[ 3 ] = "4th";
print "Array with just one element initialized: @array3 \n\n";
print 'Printing literal using single quotes: @array and \n', "\n";
print "Printing literal using backslashes: \@array and \\n\n";
Related examples in the same category