Is language Perl have stack, or I must write it?

P

Paul Lalli

Is language Perl have stack, or I must write it?

There is no built in, pre-defined "stack" structure, no. However,
Perl's default array type can be used to model stacks, queues, sets,
and other structures.

If you want to only use an array like a stack, restrict yourself to the
push and pop functions, which add and remove elements from the back of
the array, respectively.

If you want to only use an array like a queue, use the push and shift
functions, which add an element to the back, and remove an element from
the front, respectively.

perldoc -f push
perldoc -f pop
perldoc -f shift
perldoc -f unshift
perldoc -f splice

for more information on the different possibilities.

Paul Lalli
 
B

Brad Murray

(e-mail address removed) wrote:
ipc> Is language Perl have stack, or I must write it?

If you access and array with push and pop, it is a stack.

perldoc -f push
perldoc -f pop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top