[EMAIL PROTECTED] wrote:
>
> Due to forgetfulness I was recently bitten by the infamous "my() Scoped
> Variable in Nested Subroutines" problem using Apache::Registry, and it got
> me thinking about whether it is fixable.
>
> >From the diagnostics:
> This problem can usually be solved by making the inner subroutine
> anonymous, using the sub {} syntax. When inner anonymous subs that
> reference variables in outer subroutines are called or referenced, they
> are automatically rebound to the current values of such variables.
>
> I think it should be possible for Registry to pre-process the source code
> to turn all top-level named subroutines into sub refs. For example,
> convert subroutines of the form
>
> sub foo { <CODE> }
>
> into
>
> sub foo { &{ sub { <CODE> } } }
[snip]
I think it would be easier to convert
sub foo
into
local *foo = sub
That way, you don't have to parse for the matching right brace.
Something like:
s/sub\s+(\w+)/local *\1 = sub/msg; # untested - just a guess
might do the trick.
--
Dan Campbell