in reply to Re^2: typeglob reference deletes global lexical
in thread typeglob reference deletes global lexical

The code is here http://www.bivio.biz/hm/download-bOP I can't seem to distill it to the point of reproducing the problem in a short script.

Needless to say a simple implementation does not produce the bug. I've stripped all the non-essential parts out, and started mod_perl, but the failure does show up. It is reliable for a particular package and code configuration. However, changing code in other packages can cause the failure to disappear.

  • Comment on Re^3: typeglob reference deletes global lexical

Replies are listed 'Best First'.
Re^4: typeglob reference deletes global lexical
by ikegami (Patriarch) on Nov 08, 2008 at 05:15 UTC
    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.