Perl Array Assignment

Tags: Shainin Red X Problem SolvingBiology Assignment HelpEssay On Higher Education In BiharBeing An American Essay On TwitterAnalytical Essay On Invisible ManEssay On Into The Wild BookHomework Or No Homework

# Multiple elements value assignment, which creates an array with four elements, some numeric and some string.

@array = (25, "John", "Mary", -45.34); print "$array[1]\n"; # John # Direct assignment of an element with a specific index.

Each numbered item is called an element of the array, and the number assigned this element is called its index.

In per arrays have a special sigil(the prefix of the name) -- @, For example In compiled languages typically all elements of array should have the same type (and thus the same the size in bytes).

In the above example, $stuff[0] refers to the first array reference ['one', 'two', 'three' ...], $stuff[1] refers to the second array reference [7, 6, 5] and so on.

After adding the subscript to get you to the right reference, just add another index to go to the right element in that sub-array.

The follow example initializes and uses a multidimensional array in Perl; -- actually simply an array of references.

You can see that our "array of arrays" is actually an array of references to arrays.

Thus, when you assign values only to the first and, say, 1000th elements of an array, Perl will allocate memory only for two elements, not for 1000 elements.

In case the elements of the array are strings, another good model of understanding of what Perl array is the buffer of the text editor.

SHOW COMMENTS

Comments Perl Array Assignment

The Latest from mediashkola-plus.ru ©