in reply to Re: How to interact with the console (input/output) running a Perl program on “Windows Power Shell ISE”?
in thread How to interact with the console (input/output) running a Perl program on “Windows Power Shell ISE”?

When I run that "hello.pl" in PS-ISE, it prints "Hello world" fine.
But, I would like to interact with the console, using Unicode characters. When I run this program, it hangs (doesn't even print the first message, which should be straightforward):

#!/usr/local/bin/perl # Load a conversion table from CONVTABLE to %ConvTable. Then find mat +ches in a file and convert them. use strict; use warnings; use Encode; use 5.014; use utf8; use diagnostics; use autodie; use warnings qw< FATAL utf8 >; use open qw< :std :utf8 >; use charnames qw< :full >; use feature qw< unicode_strings >; my ($i,$j,$InputFile, $OutputFile,$word,$from,$to,$linetoprint); my (@line, @lineout); my %ConvTable; # Conversion hash my ($CONVTABLE, $INPUT, $OUTPUT); print 'Conversion table: opening file: E:\My Documents\Technical\Perl +\Conversion table 1.txt'."\n"; my $sta= open ($CONVTABLE, "<:encoding(utf8)", 'E:\My Documents\Techn +ical\Perl\Conversion table 1.txt'); binmode STDOUT, ':utf8'; # output should be in UTF-8 binmode $DB::OUT, ':utf8' if $DB::OUT; # for the debugger # Load conversion hash while (<$CONVTABLE>) { chomp; print "$_\n"; @line = split; $/=','; chomp(@line); # Chomp chomps a variable if its last char equals $/ $/="\n"; # Restore $/ $ConvTable{$line[0]}=$line[1]; } # end while (<$CONVTABLE>) while ( ($i,$j) = each (%ConvTable) ) { print "$i => $j\n"; } # Open file to convert print "Input to convert: enter path\\fileName: "; $InputFile = <STDIN>; chomp($InputFile); print "\$InputFile=\"$InputFile\"\n"; $sta = open ($INPUT, "<:encoding(utf8)", $InputFile); # Open output file print "OUTPUT: enter path and fileName: "; $OutputFile = <STDIN>; chomp($OutputFile); print "\$OutputFile= \"$OutputFile\"\n"; $sta = open ($OUTPUT, ">:encoding(utf8)", ">$OutputFile"); # Iterate over lines of INPUT, convert according to %ConvTable, store +in OUTPUT while (<$INPUT>) { chomp; @line = split; foreach $word(@line) { while (($from, $to) = each(%ConvTable)) { # traverse the conv +ersion table. # check if there ar +e any matches in the word and substitue $word =~ s/$from/$to/; # substitute substrings if match } # end value in %ConvTable push(@lineout, $word); } # end foreach string in the line $linetoprint = join (", ",@lineout); print ($OUTPUT, "$linetoprint\n"); $#lineout= (-1); # empty @lineout } # end while over INPUT file

Should I flush the STDOUT buffer? How to do it?

  • Comment on Re^2: How to interact with the console (input/output) running a Perl program on “Windows Power Shell ISE”?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to interact with the console (input/output) running a Perl program on “Windows Power Shell ISE”?
by LonelyPilgrim (Beadle) on Feb 18, 2012 at 19:21 UTC

    Again, why do this on the command line with STDIN and STDOUT? It seems to me like more trouble than it's worth to try do what you're doing through a console interface -- which provides usually just the bare bones of character support -- particularly if you plan on doing it through something clunky like this WPS-ISE. I'm not a GUI guy at all, but it seems like it might be worthwhile to set up a simple GUI to receive the input and print the output. Have you looked at Tk? It would give you something like Windows text boxes which ought to support your Unicode fonts. You could also have a file selector dialog.

    Update: Upon fiddling with it, I now see that the Tk interface that comes with ActivePerl now, at least, is Tkx. And it has crummy documentation. But I think it might help you.