in reply to masking password entry

The line

while (my $KeyPressed = $StdIn->InputChar(1))

should be changed to

my $KeyPressed; while (defined ($KeyPressed = $StdIn->InputChar(1)))

Replies are listed 'Best First'.
Re^2: masking password entry
by AnomalousMonk (Archbishop) on May 04, 2010 at 22:02 UTC
    my $KeyPressed; while (defined ($KeyPressed = $StdIn->InputChar(1)))

    It's possible to maintain the scoping of  $KeyPressed used in the OP code:
        while (defined(my $KeyPressed = $StdIn->InputChar(1))) {
            ...
            }

    The reason the original code 'fails' is that a '0' character entered by the user evaluates as false, and the  while loop ceases iteration in consequence.