in reply to Unable to declare local variable with "use strict".
local doesn't declare a variable. It just makes a temporarily backup of one.
You can use our to effectively disable strict 'vars' for a variable.
or#!/usr/bin/perl -w use strict; our $type; ref_test1(); sub ref_test1 { local $type="connect"; print "Here in ref_test1.\n"; ref_test2(); } sub ref_test2 { print "Type: $type\n"; print "Here in ref_test2\n"; }
#!/usr/bin/perl -w use strict; ref_test1(); sub ref_test1 { local our $type="connect"; print "Here in ref_test1.\n"; ref_test2(); } sub ref_test2 { our $type; print "Type: $type\n"; print "Here in ref_test2\n"; }
However, the following is better because it's more loosely coupled:
#!/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"; }
|
|---|