in reply to My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?

The above replies explain why the variable's scope includes the subroutine. But the "George" issue is a more subtle problem: the infamous "won't stay shared" issue (which, by the way, you would see if you enable warnings in your code). When running a CGI script with mod_perl using Apache::Registry, you can't use variables declared with my in the main script body inside subroutines, because the subroutine will have a "copy" of the variable from the first time the script is run, which is almost never what you want. Some possible solutions are:
  • Comment on Re: My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?
by Calm (Acolyte) on Apr 25, 2007 at 20:20 UTC
    Ahhhh...good explanation and thank you for those solutions. I'm very new to this, so I don't really know anything about mod_perl, Apache::Registry and Apache::PerlRun, but those should be easy search terms to look up. Also, I have the -w flag in my !# line, but I'm not sure where those warnings would be showing themselves. Maybe in this error log people keep mentioning? Looks like I need to research that as well.

    Thanks.

      Should be in the error log, yes :-) Where the log is is dependent on your apache configuration.

      Where your apache configuration is, is dependent on your apache startup scripts/system configuration. On my system (debian) it's in /etc/apache/httpd.conf. Look for the "ErrorLog" line. On my system the error log is in /var/log/apache/error.log

      I have the -w flag in my !# line
      The shebang is not recognized in your system, it's merely treated as comment. (from LP on Win32)

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!