Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there Stacks in Perl?

Status
Not open for further replies.

Netherbeast

Programmer
Jun 4, 2002
89
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?
 
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.,
(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top