Hi, this is making me crazy.
I have a subroutine/method in an object, looks kinda like this:
sub generate {
my ($self, $OBJS) = @_;
# NOTE:
# $OBJS is an array of objects, and array elements can also be arrays
+of objects
while(SOMETHING) {
if ($OBJS) { # we got anything?
if (scalar(@{$OBJS})) { # 0-length array is useless
my $OBJ = shift(@{$OBJS});
DO MEAN STUFF TO THE OBJ
}
}
}
return LA-LA;
}
The first time into the while(SOMETHING) loop everything goes as planned, as would be expected, BUT.......!!!
The second time through the loop, $OBJ has the remnants of the MEAN STUFF that was done to it.
So, after looking around and seeing about deep copying, and FreezeThaw and Clone, and trying them out, I still can't get rid of the evidence of the MEAN STUFF I did to $OBJ.
Here's an example of what I've tried, I tried to loop through the array building copies, like this:
my $OBJScopy;
foreach my $obj (@$OBJS) {
push(@{$OBJScopy}, clone($obj));
}
and the subroutine from above references $OBJScopy instead of $OBJS
but later when I try to do MEAN STUFF to $OBJ it still bears the scars of earlier mistreatment.
Why is this so difficult? What am I overlooking?
THANKS!!!!!
Tosh
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.