Arrays in Perl : Array Definition « Array « Perl






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

1.Define an array variable called @myList.
2.Create lists of number variables
3.Create lists of text variables
4.Array literal
5.String array
6.Lists Assigned to Arrays
7.An array is a named list.
8.A program that reads data into an array and writes the array.
9.Build a string array across two lines
10.Construct a string array and output its first element
11.Construct an integer array and output its first element
12.Define two dimensional array
13.An empty list is represented as parentheses with nothing in between
14.Using qw to construct a string array
15.Constructing and Dereferencing