How can I check if no elements exist further in the array to be processed by the foreach loop?
Example:
my @array = ("abc","def","ghi");
foreach my $i (@array) {
print "I am inside array\n";
#####'Now, I want it further to go if there are no elements after
#####(or it can be said if it is the last element of array. Otherwise, go to next iteration'
print "i did this because there is no elements afterwards in array\n";
}
I could think of ways to do this, but wondering if I can get it in a short way, either using a specific keyword or function. One way I thought:
my $index = 0;
while ($index < scalar @array) {
##Do my functionality here
}
if ($index == scalar @array) {
print "Proceed\n";
}