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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.