in reply to Re^2: Unable to declare local variable with "use strict".
in thread Unable to declare local variable with "use strict".

So, I can not use local with use strict?
Sure you can. Note that anyone with a reply suggesting you replace the 'local' with 'my' doesn't understand why you are getting the error.

The problem is the extension of the scope. You do local $var in a certain scope. But the other use is in a different scope. That is the cause of the error. Replacing the local with my doesn't solve that.

Replies are listed 'Best First'.
Re^4: Unable to declare local variable with "use strict".
by ikegami (Patriarch) on Mar 27, 2010 at 01:50 UTC

    Note that anyone with a reply suggesting you replace the 'local' with 'my' doesn't understand why you are getting the error.

    I did just that, and I beg to differ. The solution I recommended uses my and works quite well. While changing to my alone is not enough, it can definitely be part of the solution.

      I beg to differ. The solution I recommended uses my and works quite well. While changing to my alone is not enough..

      You're doing it again.

        Did you run it? Maybe if you told us what error you got?

        #!/usr/bin/perl -w use strict; ref_test1(); sub ref_test1 { print "Here in ref_test1.\n"; ref_test2("connect"); } sub ref_test2 { my ($type) = @_; print "Type: $type\n"; print "Here in ref_test2\n"; }
        Here in ref_test1. Type: connect Here in ref_test2