|
Posted by xhoster on August 26, 2005, 6:10 pm
Please log in for more thread options
> wrote:
>
> [snip]
>
> > BTW, @Deep_copy_stack doesn't seem to be lexically scoped. I dont' see
> > how that would cause this particular problem, but I'd fix it anyway
> > just in case.
>
> Presumably, @Deep_copy_stack is scoped outside of the _deep_copy
> subroutine so that recursive calls to _deep_copy will be accessing the
> same version of @Deep_copy_stack to prevent infinite recursion in the
> case of a circular reference.
Yep, that is the way I do it, too. Until I learn my lesson, and go back
and change it is so that the master call passes in a ref to a (possibly
anonymous) array or hash, and every recursive invocation simply passes that
ref along:
foo($structure_to_be_recursed, {}); ## or [] rather than {}
sub foo {
my $struct=shift;
my $guard=shift;
## blah blah blah
foo($new_struct,$guard);
## blah blah blah.
};
> The OP has shown us only the _deep_copy
> subroutine, so we can't tell.
True, but it seems to me that it must be either a lexical with the
potential to become unshared (since this is run in mod_perl), or a
non-lexical variable. Either way, it makes me uncomfortable. I don't have
any reason to think that this is the problem, but whenever Perl behaves in
a way that seems mysterious my first step is to tighten scopes and convert
to lexicals, and that often either clears up or eliminates the mystery
(either directly or indirectly)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
|