this program should execute three times but is executing only twice. Can anyone explain how this foreach loop will work in perl.
#!/usr/bin/perl
use strict;
use warnings;
my @arr=("sandeepr", "vijay","vikas");
for my $i( @arr)
{
print @arr;
my $b=pop(@arr);
print "\n $b";
}
print $i; You are also modifying the array you are iterating over, which is generally a bad idea and can cause unexpected results. Better to copy the array that you wish to manipulate.$aand$bhave a special purpose, see perldoc -f sortfor (1..3) { print @arr; }