in reply to Unable to declare local variable with "use strict".

It looks like fuzzy thinking to me. You have two subroutines and you want then to share a variable, but you don't want that variable visible anywhere else. The answer to this is closures.

Since subroutines form a closure, the easiest way is to declare ref_test2() inside the body of ref_test1(). ref_test2() will have access to everything ref_test1() does, Note that creating a named subroutine puts a global entry in the symbol table, ref_test2() could still be called from outside of ref_test1() and still see the exact same variables.

But I don't like nested subroutines under any circumstances, so I wouldn't go there. I'd do it like this:

{ # start closure my $type; sub ref_test1() { ... } sub ref_test2() { ... } } # end of closure

which allows both to read/write/whatever $type as much as they like, yet $type is still invisible to the outside world.

- doug

PS: Someone posted that since ref_test1() was calling ref_test2() directly, then you should pass $type as a parameter, and I agree completely. I'm guessing that this example is simplified, and that in the real example ref_test2() can be called from other places too.