...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.
In reply to 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
in thread My, subroutines, scope, and CGI – Why can I see a private (my) variable in a subroutine but it doesn’t get updated?
by Calm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |