foreach(@stack1){ my $qq = pop(@stack1); print "$qq popped from end of queue\n"; print "left on stack : @stack1 \n"; print "stack size is $#stack1 \n"; }
You are iterating on @stack1 and, at each iteration, tou pop the last element from the stack. When foreach reaches the point where elements have been popped it stops.
You can try:
while(@stack1){ my $qq = pop(@stack1); print "$qq popped from end of queue\n"; print "left on stack : @stack1 \n"; print "stack size is $#stack1 \n"; }
So your loop iterates until @stack1 is empty.
Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."
In reply to Re: using foreach
by psini
in thread using foreach
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |