>># NOTE:
>># $OBJS is an array of objects, and array elements can also be arrays of objects

I should have read the question better before I answered :-)
The code I gave will only dereference down 1 layer.
The code below will explain this better, I hope.
Anyway, I think what you really want is Clone.
I just downloaded it to test this code, and already I see it as an invaluable tool in my Perl toolbox.
Here is an example of how my earlier code fails, and how Clone can help you.

Good luck

thinker

#!/usr/bin/perl -w use strict; use Clone qw(clone); my $original =[1,2,[3,4,5]]; my $shallow_original=$original; my $deep_original=[@$original]; #deep, but not deep enough!! my $clone_original=clone($original); # this behaves fine. $original->[1]=42; $original->[2][1]=77; print "original: @$original\n"; print "shallow: @$shallow_original\n"; print "deep: @$deep_original\n"; print "shallow[2][1]: $shallow_original->[2][1]\n"; print "deep[2][1]: $deep_original->[2][1]\n"; print "clone[2][1]: $clone_original->[2][1]\n";
The output of which is
original: 1 42 ARRAY(0x80cf9a4) shallow: 1 42 ARRAY(0x80cf9a4) deep: 1 2 ARRAY(0x80cf9a4) shallow[2][1]: 77 deep[2][1]: 77 clone[2][1]: 4

In reply to Re: Re: how do I copy an array of objects? by thinker
in thread how do I copy an array of objects? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.