Good morning all. This is my first question/post/etc here, so please forgive me if I completely get it all wrong!

OK, I am having a little bit of an issue with some code developed for a Windows environment, that is not behaving as it should. The code was originally developed by another person using active states distribution of V5.6 (where it worked just fine!) and relates to (as far as I can see) the use of the Win32::Console module

What is supposed to happen is a question is supposed to be displayed in the cmd window, which the user adds input to, another question asked, new input, etc. The input is then used as variables within the script. The cruncher is the code works fine when using V5.6, but fails miserably when using V5.8

The issue I am getting is that the questions do not appear until after you enter the input. As you can guess, this is rather frustrating. The code responsible is as follows:

#!c:\perl\bin\perl.exe -w # use strict; use Win32::Console; use Time::Local; my $CONSOLE = new Win32::Console(STD_INPUT_HANDLE); my %vals = ('cuname'=>'','defolder'=>'','cutoffdt'=>''); my %labs = ('cuname'=>'Customer Import Folder','defolder'=>'DE SubFold +er','cutoffdt'=>'Cutoff Date ddmmyy'); system "cls"; my $console_mode = $CONSOLE->Mode(); my $echo_on = (ENABLE_PROCESSED_INPUT) | (ENABLE_ECHO_INPUT); my $echo_off = (ENABLE_PROCESSED_INPUT); $CONSOLE->Mode($echo_on); $CONSOLE->Title("Change Backdated DE files"); my $promptstr = " "; my $seq = 0; foreach my $val ('cuname','defolder','cutoffdt') { $promptstr = sprintf('Enter %-25.25s = ',"\u$labs{$val}"); $CONSOLE->Mode($echo_off); print "$promptstr"; $_=''; my $chr = ''; READLINE: for(;;) { $chr = $CONSOLE->InputChar(1); last READLINE if ($chr eq "\r"); next READLINE if ($chr eq "\n"); if ($chr lt ' ') { $seq = ord($chr); # # allow backspace to edit # if ($seq == 8 && $_ ne '') { chop; # trim the last char print "$chr $chr"; # and overprint with a space on screen } next READLINE; } $_ .= $chr; if ($labs{$val} =~ /password/i) { print '*' ; } else { print "$chr" ; } } &err_exit(0) unless($_ && $_ !~ /^exit$/i); $vals{$val} = $_; print "\n"; } $CONSOLE->Mode($console_mode); # restore default mode

From here, the input is used as variables in the program.

I have tried a few different bits and pieces (my perl knowledge is at the +1 from newbie stage at the moment!), such as a dummy print around print "$promptstr";, which work fine. I have also added a newline on the print command above, which then makes the prompt print, but puts the cursor on a new page.

Can anyone give me some advice on what I should do and where I should look to get this working as it should. Any help would be appreciated!!

Cheers!


In reply to Win32::Console problem by hoffy

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.