...
Code Block | ||
---|---|---|
| ||
my @array = (1, 2, 3); # array contains 3 elements initialized print "Array size is $#array\n"; # 2 $array[5] = 0; # array grows to contain 6 elements so that reference is valid print "Array size is $#array\n"; # 5 my $value = $array[7]; # array unchanged + uninitialized value warning $value = $array[-7]; # array unchanged + uninitialized value warning if (exists $array[9]) { # false, array unchanged print "That's a big array.\n"; } print "Array size is $#array\n"; # still 5 |
This automatic growth occurs only if the index provided is positive and the array value is being written, not read, and not passed to a testing function like exists()
or defined()
.
...