in reply to Re^6: Unable to declare local variable with "use strict".
in thread Unable to declare local variable with "use strict".
Generally, when people speak of a 'closure' in Perl, people mean a specific kind of subroutine, not a block, as your comment seems to indicate.
I disagree. Any block that creates scoped variables is a closure in my book.
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.
While you are absolutely right, who cares? Are you saying that everyone who creates a class has to build a potentially exhaustive set of classes and subclasses so that no one can see things that don't belong to them?
Information hiding is a wonderful thing, but there is no need to go overboard with it. If you've got it down to where just a handful of localised subroutines (same closure) can get to the protected data, then you've done well enough.
- doug
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Unable to declare local variable with "use strict".
by JavaFan (Canon) on Mar 29, 2010 at 19:02 UTC | |
by ikegami (Patriarch) on Mar 29, 2010 at 20:27 UTC | |
by JavaFan (Canon) on Mar 29, 2010 at 21:05 UTC | |
by ikegami (Patriarch) on Mar 29, 2010 at 21:31 UTC | |
by doug (Pilgrim) on Mar 30, 2010 at 09:24 UTC |