in reply to using foreach

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."

Replies are listed 'Best First'.
Re^2: using foreach
by Anonymous Monk on Jul 25, 2008 at 11:44 UTC
    Thanks for your wisdom.. much appreciated. -MisterT