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

Dan Boger dan at peeron.com
Tue May 27 10:11:03 PDT 2008


On Tue, May 27, 2008 at 9:52 AM, Neil Heller <nheller at silcon.com> wrote:

>  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 think (but can't be sure since you didn't post what you tried) that you're
running into a precedence issue.  If you type:

  push $a1ref[0]->[0], "value";

Push will complain since it wants an array as it's first argument, not an
array reference.  The way to get around it is to dereference the array:

  push @{$a1ref[0]->[0]}, "value";

Same will work for any of the array manipulation commands (shift, pop,
unshift, splice, etc).

HTH!

Dan

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


More information about the SanFrancisco-pm mailing list