Sounds like a closure problem.
{ my $var = 'this string'; sub test1 { print("var = $var\n"); } sub test2 { eval(' print("var = $var\n"); '); } sub test3 { $var; eval(' print("var = $var\n"); '); } } test1(); # var = this string test2(); # var = (undef) test3(); # var = this string
Perl doesn't know that test2 will need $var, so it doesn't capture $var.
Is your my variable inside curlies? Remember that mod_perl Registry scripts are placed inside a function and therefore inside curlies.
Update: Exiting any scope will cause closures and thus the problem. Curlies create scopes, but so do do, require and use as tye points out in his reply. The following will also exhibit the problem:
# Module.pm pacakge Module; my $var = 'this string'; sub test1 { print("var = $var\n"); } sub test2 { eval(' print("var = $var\n"); '); } sub test3 { $var; eval(' print("var = $var\n"); '); }
# script.pl use Module; Module::test1(); # var = this string Module::test2(); # var = (undef) Module::test3(); # var = this string
In reply to Re: quantum behavior in perl?
by ikegami
in thread quantum behavior in perl?
by b4swine
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |