If we have array then we can do following:
my @arr = qw(Field3 Field1 Field2 Field5 Field4);
my $last_arr_index=$#arr;
How do we do this for ar
The reason you probably need to access the last index is to get the last value in the array reference.
If that is the case, you can simply do the following:
$arr_ref->[-1];
The ->
operator dereferences. [-1]
is the last element of the array.
If you need to count the number of elements in the array, there's no need to do $#{ $arr_ref } + 1
. DVK has shown a couple of better ways to do it.