Perl:Creating an Array

From Progzoo
Jump to navigation Jump to search

Create an Array Literal

You can initialise the array to a specific list of values:


[Font] [Default] [Show] [Resize] [History] [Profile]

Create an Array Reference

Make sure you understand the difference between an array variable (which starts with @), and a scalar variable whose value is a reference (like a pointer) to an array. You can use square brackets to create an array reference literal:


[Font] [Default] [Show] [Resize] [History] [Profile]

Create a two dimensional Array Literal

Because the elements of arrays must be scalars (if you put an array into list context, it will just "flatten" into its elements), you must use references for the inner subarrays of two-dimensional arrays:


[Font] [Default] [Show] [Resize] [History] [Profile]

Create a String Array using split

The split function can be useful for creating string array:


[Font] [Default] [Show] [Resize] [History] [Profile]