in reply to Re^2: Using exists to check element in array
in thread Using exists to check element in array

Its because the 'high level' concept of an Array is that it is a string of 0 to n items. So all items in the array always exist conceptually.

So if you want to know if index x 'exists' in the array, simply do either: (x <= $#array) or (x < scalar @array).

If you haven't set an array index to a value, then its value will be undef and you can check this simply with (defined $array[x]). If x is beyond the length of array, this will not change the length of the array. However if you assign an index to a value - including undef, the array will expand in size to at least that index.

.