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

Garth Webb garth.webb at gmail.com
Tue May 27 11:35:43 PDT 2008


On Tue, May 27, 2008 at 9:52 AM, Neil Heller <nheller at silcon.com> wrote:
> 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]
>
>            Portland
>
>            Salem
>
>            Beaverton
>
>
>
>
>
> 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.

Where have you looked so far?  Where did those sources fall short?
What have you tried already?  Examples of all these things will help
get you better answers since:

* It shows how you've already helped yourself; many people with good
answers won't respond if they think they'll be used a replacement for
'man', 'perldoc -q' or google.
* It helps people not give answers to things you've already figured
out. A first reading of this question makes it sound like you haven't
read 'man perlfunc' to discover the 'pop' and 'push' methods, but it
maybe you already have and are just having a problem with the syntax
of multidimensional arrays.
* If there's a specific bit of documentation that you tried but didn't
make sense we can help clarify that rather than just point you back at
it because we didn't know you already read it.

So, what have you tried?  What docs didn't make sense?

Garth

>
>
> I appreciate any help I can get.
>
>
>
> Neil Heller
>
>
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
>


More information about the SanFrancisco-pm mailing list