in reply to Sub Definitions Within Subs: Best Way to Exploit
update: Please note that there are some great examples of using nested subs to create closures, especially a great example on using this technique to create a static variable. This can be very useful if a certain sub should set a global value once and only once, so it computes the value and then creates an accessor routine that refers to the variable.sub foo { my $bar = sub { print "world!\n" }; print "Hello\n"; &$bar; #also can be written as: $bar->(); } foo(); #&$bar here will not work since $bar is only valid inside foo.
|
|---|