mod_perl? Don't use "global" lexicals in mod_perl Registry script. Had you turned on warnings, you would have gotten one. mod_perl wraps your script in a function, so you basically get
sub mod_perl_wrapper { ##### Begining of script ##### use strict; use warnings; my $global = $_[0]; # Say some value from the request. sub foo { # Warms 'Variable "$global" will not stay shared' print("$global\n"); } foo(); ##### End of script ##### } mod_perl_wrapper(4); # First request prints "4" mod_perl_wrapper(5); # Subsequent requests also prints "4"

Use a package variable instead.

sub mod_perl_wrapper { ##### Begining of script ##### use strict; use warnings; local our $global = $_[0]; # Say some value from the request. sub foo { print("$global\n"); } foo(); ##### End of script ##### } mod_perl_wrapper(4); # 1st request prints "4" mod_perl_wrapper(5); # 2nd request prints "5"

I almost mentioned this earlier. I can't believe you went through all this trouble rather than turning on warnings. Even if you don't normally use them for whatever reason, adding use strict; and use warnings; is the first thing you should do when you have a problem you can't explain.


In reply to Re^4: typeglob reference deletes global lexical by ikegami
in thread typeglob reference deletes global lexical by robnagler

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.