I have a variable currentUser in a sub routine. It carries through to one subroutine, but does not carry through to another subroutine. How can I pass a variable through multiple subroutines while keeping the value?
sub login {
&app_header;
print <<EOF;
<form name="macform" method="POST" enctype="application/x-www-form-urlencoded" action="$fullurl">
...stuff
EOF
}
sub html_menu {
$me = $currentUser;
print $me;
print <<EOF;
<form name="menuform" method="POST" enctype="application/x-www-form-urlencoded" action="$fullurl">
..stuff
EOF
&app_list_button;
print "<br>";
&app_search_button;
print "<br>";
&app_edit_button;
print "</div>";
}
When I attempt to do the same thing the html_form sub does with currentUser in a new sub called after html_form), the variable does not display as what the user entered during login.
…and so on.
Passing a variable as argument is done through the
@_variable. You should not attempt to use global variables, it is not a good way to do it. You can do it like so:Or by using
shift,popand the other methods of manipulating arrays, like I above usedshift.If you are not already doing so, I recommend very strongly that you use
It will help you solve many simple problems.