Given that scripts tend to grow as variations in the requirement come along, it is important that they are as maintainable as possible. The use of lots of global variables for static storage causes maintenance problems because the code and variables are not in the same place, creating the need to have to search a growing amount of code to solve functionality coded in a localised place. Encapsulation is key to why O-O solves complexity and closure is a related concept.
-M
Free your mind
Comment on Re^2: static storage in a local subroutine?
Yes, it's beginning to make sense: "Barrie Slaymaker calls closures "inside-out objects:" objects are data that have some subroutines attached to them, and closures are subroutines that have some data attached to them."
sub make_counter {
my $start = shift;
return sub { $start++ }
}
my $from_ten = make_counter(10);
my $from_three = make_counter(3);
print $from_ten->(); # 10
print $from_ten->(); # 11
print $from_three->(); # 3
print $from_ten->(); # 12
print $from_three->(); # 4