in reply to Re: My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?
in thread My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?
...then it won't even compile under strict because the sub refers to a variable ($user_name) that's not available in its scope. Put the login sub inside the braces that have my $user_name, and it will work again. See?
I understand. It didn't sound that way from the book, but I understand and can adjust accordingly.
This is something that mod_perl does.
Can I stop it? Should I? Should I just reinitialize the variable in the subroutine the same way I do in the main script? Why does it do that?
No. In general, you should almost always use my instead of local. If you want global variables, look at our or vars.
Thank you, and will do.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?
by Joost (Canon) on Apr 25, 2007 at 19:01 UTC |