Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#arrays as stacks my @stack1 = qw/this is a good feature/; print "initial array contains : @stack1\n"; push(@stack1,"in"); print "@stack1\n"; push(@stack1,"perl"); print "@stack1\n"; my $var = pop(@stack1); print "$var popped of arraystack which now contains : @stack1\n"; push(@stack1, 7); push(@stack1, 8); $var = pop(@stack1) + pop(@stack1); print"$var\n"; #arrays as queues print "@stack1\n"; unshift(@stack1,"thing"); print "@stack1\n"; 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"; }
##output initial array contains : this is a good feature this is a good feature in this is a good feature in perl perl popped of arraystack which now contains : this is a good feature +in 15 this is a good feature in thing this is a good feature in in popped from end of queue left on stack : thing this is a good feature stack size is 5 feature popped from end of queue left on stack : thing this is a good stack size is 4 good popped from end of queue left on stack : thing this is a stack size is 3 a popped from end of queue left on stack : thing this is stack size is 2 C:\Documents and Settings>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using foreach
by psini (Deacon) on Jul 25, 2008 at 11:18 UTC | |
by Anonymous Monk on Jul 25, 2008 at 11:44 UTC | |
|
Re: using foreach
by pjotrik (Friar) on Jul 25, 2008 at 11:57 UTC | |
|
Re: using foreach
by kabeldag (Hermit) on Jul 25, 2008 at 11:50 UTC | |
|
Re: using foreach
by broomduster (Priest) on Jul 25, 2008 at 12:20 UTC | |
|
Re: using foreach
by thezip (Vicar) on Jul 25, 2008 at 23:57 UTC | |
|
Re: using foreach
by GrandFather (Saint) on Jul 25, 2008 at 22:00 UTC |