R
Roman Rodriguez
Can anyone tell me if you can pass scalars and list to subroutines? if so,
what is the syntax? what am I doing wrong in the following code?
It seems the correct value is not returned because my subroutine doesn't
appear to be recieveing the parameter from the caller.
sub setMainMenuOption
{
my $SelectedOption = $_; #set $SelectedOption to value passed in
(from user)
if( $SelectedOption eq 's')
{
return("Sleep");
}
return("INVALID");
{
$UserInput = "S\n"; #simulate STDIN user input of the capital letter 'S'
print "\n\$UserInput: $UserInput";
chomp($UserInput);
print "\n\$UserInput after CHOMP: $UserInput";
$UserInput = lc($UserInput);
print "\n\$UserInput after lc(): $UserInput";
$Menu = &setMainMenuOption($UserInput);
print "\n\$Menu after return = $Menu";
exit;
results in the following output:
$UserInput: S
$UserInput after CHOMP: S
$UserUnput after lc(): s
$Menu after return = INVALID
when I step through this code I see that "$_" in the subroutine is not
properly recieving the arguement and therefore variable $SelectedOption is
remaining as "".
what is the proper way to pass arguments to a subroutine?
Thanks!
-RR
Thanks
-RR
what is the syntax? what am I doing wrong in the following code?
It seems the correct value is not returned because my subroutine doesn't
appear to be recieveing the parameter from the caller.
sub setMainMenuOption
{
my $SelectedOption = $_; #set $SelectedOption to value passed in
(from user)
if( $SelectedOption eq 's')
{
return("Sleep");
}
return("INVALID");
{
$UserInput = "S\n"; #simulate STDIN user input of the capital letter 'S'
print "\n\$UserInput: $UserInput";
chomp($UserInput);
print "\n\$UserInput after CHOMP: $UserInput";
$UserInput = lc($UserInput);
print "\n\$UserInput after lc(): $UserInput";
$Menu = &setMainMenuOption($UserInput);
print "\n\$Menu after return = $Menu";
exit;
results in the following output:
$UserInput: S
$UserInput after CHOMP: S
$UserUnput after lc(): s
$Menu after return = INVALID
when I step through this code I see that "$_" in the subroutine is not
properly recieving the arguement and therefore variable $SelectedOption is
remaining as "".
what is the proper way to pass arguments to a subroutine?
Thanks!
-RR
Thanks
-RR