in reply to Re^2: Difference between exists and defined (updated)
in thread Difference between exists and defined

I don't remember where I read it (probably in the Panther book) but Perl arrays are designed to easily compete with linked lists, while keeping the benefits of indexed access.

That is to allow dynamic growth on both ends in a very dynamic way.

An array has an internal index for the first and last element and allocates twice as much space as reserve for push or unshift.

Basically only the range between the first and last existing element need to be stored, plus mentioned reserve.

The existing elements are kind of pointers to scalars which are allocated separately.

Allocation of new space is only needed if the reserve elements are filled, since this happens in exponential steps of doubling* it's statistically very efficient.

Shrinking the array happens just by adjusting the indices for the first and last element.

HTH

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

update

see here Shift, Pop, Unshift and Push with Impunity!

*) not sure anymore about the doubling, maybe confusing that part with hashes.

  • Comment on Re^3: Difference between exists and defined