The only other thing I can think of is that you did want $closure in ... to reference to same variable.
Exactly.
With this syntax:
{ my $closure; sub x1{ ... } sub x2{ ... } sub x3{ ... } ... }
I can share the closure between as many subroutines as I need.
With embedded state, the closure's scope is restricted to the one subroutine.
I could do:
{ state $closure; sub x1{ ... } sub x2{ ... } sub x3{ ... } ... }
But then state has no advantage over the simple closure.
I did start to use state when it first appeared (there are probably several examples here somewhere), but after the third or fourth time of having to revert it back to a standard closure as needs changed, I simply stopped using it.
In reply to Re^7: Experimental features: autoderef vs postfix deref
by BrowserUk
in thread Experimental features: autoderef vs postfix deref
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |