Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The first time into the while(SOMETHING) loop everything goes as planned, as would be expected, BUT.......!!!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; }
and the subroutine from above references $OBJScopy instead of $OBJSmy $OBJScopy; foreach my $obj (@$OBJS) { push(@{$OBJScopy}, clone($obj)); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how do I copy an array of objects?
by thinker (Parson) on Nov 12, 2001 at 16:13 UTC | |
by thinker (Parson) on Nov 12, 2001 at 21:02 UTC |