Hi My program was to ask user a password which should be entered with '*' masking. And after user entered the password, user will be asked to enter another Input, text of which will be visible. For linux its ok. But for windows i am trying to use Windows::Console The code is

use warnings; use Win32::Console; sub readPasswordWindows { my $pwdText = shift; my $inputValue = ""; my $StdIn = Win32::Console->new(STD_INPUT_HANDLE); my $orig_mode = $StdIn->Mode(); $StdIn->Mode(ENABLE_PROCESSED_INPUT); my $Password = promptPassword($StdIn, $pwdText, '*'); print "\nPassword = $Password\n"; $StdIn->Mode($orig_mode); return $Password; } sub promptPassword { my ($handle, $prompt, $mask) = @_; my ($Password); local $| = 1; print $prompt; $handle->Flush; while (my $Data = $handle->InputChar(1)) { last if "\r" eq $Data; if ("\ch" eq $Data ) { if ( "" ne chop( $Password )) { print "\ch \ch"; } next; } $Password .= $Data; print $mask; } return $Password; } sub readInput(){ my $ip =""; print " \n Input : "; $ip = <STDIN>; print "\n input was = $ip"; return; } my $pw = readPasswordWindows("Enter password: "); readInput();

......................................... This program gives me error in taking input and says: use of uninitialized value in print for $ip Now if i modify my program a bit by calling the readInput(); as last statement from function promptPassword() it all works fine. The code for which is

use warnings; use Win32::Console; sub readPasswordWindows { my $pwdText = shift; my $inputValue = ""; my $StdIn = Win32::Console->new(STD_INPUT_HANDLE); my $orig_mode = $StdIn->Mode(); $StdIn->Mode(ENABLE_PROCESSED_INPUT); my $Password = promptPassword($StdIn, $pwdText, '*'); print "\nPassword = $Password\n"; $StdIn->Mode($orig_mode); readInput(); return $Password; } sub promptPassword { my ($handle, $prompt, $mask) = @_; my ($Password); local $| = 1; print $prompt; $handle->Flush; while (my $Data = $handle->InputChar(1)) { last if "\r" eq $Data; if ("\ch" eq $Data ) { if ( "" ne chop( $Password )) { print "\ch \ch"; } next; } $Password .= $Data; print $mask; } return $Password; } sub readInput(){ my $ip =""; print " \n Input : "; $ip = <STDIN>; print "\n input was = $ip"; return; } my $pw = readPasswordWindows("Enter password: ");

as far as i am concerned both the programs are same. But a tweaking in program gives problem with using stdin


In reply to Problem with Windows Console input by anshulzunke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.