I looked through a few answers regarding this warning, but they also did not help me, and I really don't understand what Perl is doing here at all. Here is what I want to do:
sub outerSub { my $dom = someBigDOM; ... my $otherVar = innerSub(); return $otherVar; sub innerSub { my $resultVar = doStuffWith($dom); return $resultVar; } }
So basically, I have a large DOM object stored in $ dom, which I don't want to pass on the stack if possible. In outerSub, something happens that requires results from innerSub. innerSub needs access to $ dom. When I do this, I get this warning: "The $ dom variable will not remain open."
What? I do not understand:
Does this warning here? Will my supposed logic work here or will there be strange events?
If this is not as intended: is it possible to do this? Make local var visible to nested sub? Or is it better to just pass this as a parameter? Or is it better to declare "our" variable?
If I push it as a parameter, will the whole object with all its data (may have several MB) be on the stack? Or can I just pass something like a link? Or does Perl treat this parameter as a link on its own?
In "Variable $ foo will not remain public" Warning / error in Perl when calling a subroutine , someone is talking about an anonymous sub that will make this possible. I did not understand how this works, I have never used anything like this.
I donβt understand this explanation at all (maybe English is not my first language): "When the internal subprogram is called, it will see the value of the variable of the external subprogram, as it was before and during the first call of the external subprogram, in this case, after the first call is completed external routines, internal and external routines will no longer have a common value for the variable. ":
What does "first call an external routine mean?" means "
I mean: first I call the outer sub. The outer sub calls the inner sub. The outside, of course, still works. Once the outer part is completed, the inner part will be finished. Then how does this still apply when the inside is already completed? What about the "first" call? When the "second" call occurs ... sorry, this explanation bothers me to the end.
Sorry for the many questions. Perhaps someone can at least answer some of them.
variables perl local
jackthehipster
source share