> Hello,
>
>     I got the following function online but and receiving the error and
> do not know why ?
> Use of uninitialized value in string at ./sat-main.pl line 211, <STDIN>
> line 1
>
> Here is the code:
>
> my $input;
>
> $input = &user_func("Enter command ");
>
> sub user_func {
>     my $user_input;
>     my ($promptString,$defaultValue) = @_;
>
>     if ($defaultValue) {
>         print $promptString, "[", $defaultValue, "]: ";
>     } else {
>         print $promptString, ": ";
>     }
>
>     $| = 1;               # force a flush after our print
>     $user_input = <STDIN> ;   # get the input from STDIN (presumably the
> keyboard)
>
>     chomp ($user_input);
>
>     if ("$defaultValue") { ## Line 211 ??
>         return $user_input ? $user_input : $defaultValue;    # return $_
> if it has a value
>     } else {
>         return $user_input;
>     }
> } ## End of prompt_user
>
> --


$default_value is undefined as you are passing only one argument to your sub
user_func(). The argument is being consumed by $promptString.

A better check instead of
 if ("$defaultValue")
would be
 if (defined $defaultValue)



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to