in reply to Re^5: Unable to declare local variable with "use strict".
in thread Unable to declare local variable with "use strict".
Closures are typically unnamed subroutines, holding a reference to their private instance of a variable (although such a variable may be shared between more than one subroutine). In your case, the subroutines are named, and there will only be once instance of $shared_variable.
Note also that your technique doesn't scale very well. Suppose you have subroutines sub1, sub2, sub3 and sub4. sub1 and sub2 want to share a variable $var1, sub2 and sub3 want to share a variable $var2, sub3 and sub4 want to share variable $var3, and sub4 and sub1 want to share $var4. In effect, you end up with all variables visible to all subroutines. An extra block doesn't really buy you much.
|
|---|