in reply to Re^2: Why are closures cool?
in thread Why are closures cool?
The 'brokenness' comes when you have a named sub inside another subroutine. If you try this:
You'll get a "variable will not stay shared" warning, and will not get the results you expect. This happens alot with Apache::Registry novices because people will write subroutines with global (i.e. my variables at the outermost scope) variables, and Apache::Registry wraps the entire script into a subroutine of its own, so you end up with a situation like the above (the answer being to not use globals, or put the subroutines and their globals into a package of their own).use strict; use warnings; sub function { my $i = 0; sub test { print ++$i,"\n"; } test(); test(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Why are closures cool?
by Aristotle (Chancellor) on Jan 13, 2002 at 01:38 UTC | |
by tilly (Archbishop) on Jan 13, 2002 at 02:40 UTC | |
by demerphq (Chancellor) on Jan 14, 2002 at 18:35 UTC | |
by tilly (Archbishop) on Jan 14, 2002 at 18:51 UTC | |
by Aristotle (Chancellor) on Jan 13, 2002 at 08:36 UTC | |
by tilly (Archbishop) on Jan 13, 2002 at 09:02 UTC | |
by Aristotle (Chancellor) on Jan 13, 2002 at 17:26 UTC | |
|