Apr 17, 2003 #1 Netherbeast Programmer Joined Jun 4, 2002 Messages 89 Location US Is there a Stack in perl and im just not finding it in books? If there isn't a Stack, is the best way to make one using an Array?
Is there a Stack in perl and im just not finding it in books? If there isn't a Stack, is the best way to make one using an Array?
Apr 17, 2003 #2 bandisr MIS Joined May 1, 2001 Messages 4 Location IN Hi, You can use built-in functions push and pop on arrays to get the behaviour of a stack. The following code may help you my @stack; #its an array #push some elements push @stack,1; push @stack,2; #get the length of the stack $len=$#stack+1; #pop the elements for ($i=0;$i<$len;$i++) { $top = pop @stack; print $top; } #now the stack is empty Sreekanth Reddy Bandi, Persistent Systems Pvt. Ltd., (http://www.persistent.co.in) Upvote 0 Downvote
Hi, You can use built-in functions push and pop on arrays to get the behaviour of a stack. The following code may help you my @stack; #its an array #push some elements push @stack,1; push @stack,2; #get the length of the stack $len=$#stack+1; #pop the elements for ($i=0;$i<$len;$i++) { $top = pop @stack; print $top; } #now the stack is empty Sreekanth Reddy Bandi, Persistent Systems Pvt. Ltd., (http://www.persistent.co.in)