[sf-perl] Pushing and Popping an array on the heap

Neil Heller nheller at silcon.com
Tue May 27 09:52:37 PDT 2008

Some of the advantages of using an array are the push and pop functions.


The following instantiates a reference on the stack that points to an
(anonymous) empty array on the heap:


What I would like to do is:


1.       Instantiate a reference on the stack that points to an empty,
anonymous array on the heap.

2.       "push" a reference ($a2ref) into the original anonymous array that
points to a secondary, anonymous array

3.       "push" a series of references into the array referenced by $a2ref


An example might look something like the following:


$a1ref = [undef];

(The values to be pushed are as follows);


     Washington           $a1ref->[0]

           Seattle         $a1ref[0]->[0]

           Olympia         $a1ref[0]->[1]

           Tacoma          $a1ref[0]->[2]


     Oregon               $a1ref->[1]






Finally, I would like to pop (or shift) values from $a1ref followed by the
individual members of the secondary array (such as $a1ref[0]->[0]).


The problem is that I don't have a clue (nor am I able to find) how to use
(or the syntax involved to) "push" (or unshift) and "pop" (or shift) values
into and out of this described data structure.


I appreciate any help I can get.


Neil Heller


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080527/f0cad809/attachment.html 

More information about the SanFrancisco-pm mailing list