It was inside an "if". I got it to work, but I'm curious if there is a limit to how deep into a number of nested blocks this call can be before it is out of scope. Is this ever an issue?
sub block {
my $img = something->new();
if (1) {
# $img should be in scope here still
}
}
unless the thing was created inside an if block with "my" and went out of scope immediately after and then was used outside the if block.
On your last question though, there shouldn't be any issue of a number of nested blocks, as long as the variable they're using is in the same scope that their line of blocks also belongs to (and provided that variable wasn't overwritten by another local variable from the scope of another block between them). Perl won't even warn about if a block create a "my" variable with the same name as one in a higher scope (only if you do "my" twice in the same block for the same variable).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.