http://www.perlmonks.org?node_id=1011576


in reply to using win32::guitest in non english OS

read perlunitut: Unicode in Perl#I/O flow (the actual 5 minute tutorial) and see File::BOM and Encode::Detective/Encode::Guess and try
use autodie;
open my($fh), '<:via(File::BOM)', $filename ;
  • Comment on Re: using win32::guitest in non english OS

Replies are listed 'Best First'.
Re^2: using win32::guitest in non english OS
by cstar (Initiate) on Jan 04, 2013 at 09:26 UTC

    I have some chinese text in a inputfile encoded in utf8 format. I just want to read the text from the file and keep that text in a variable for further use. But when i am trying to print the line which is read, i am getting some text in Chinese, but different from what is present in the input file. Plese guide me in how to get the exact text present in input file

    use File::BOM; use Cwd; use Encode; use Encode::Detective; use strict; use warnings; my $filename=cwd().'/saml.txt'; File::BOM::open_bom(FH, $filename, ':utf8'); my $line=<FH>; my $encoding = Encode::Detective::detect ($line); print "encoding - $encoding\n"; binmode(STDOUT, ":utf8"); print "*$line*\n";

      But when i am trying to print the line which is read, i am getting some text in Chinese, but different from what is present in the input file.

      What do you mean "getting?"

      Have you checked the bytes, how are they different?

      Try ":encoding(UTF-8)"

      see Re^2: Perl / FileFind or ...

        I will explain my problem with below 2 scripts

        Script 1:

        use Encode; use Win32::GuiTest qw(FindWindowLike); open(MYFILE, '<:encoding(UTF-8)',"saml.txt") || die "cannot open: $!" +; open(OUTFILE,'>:encoding(UTF-8)',"out.txt") || die "cannot open: $!"; $line=<MYFILE>; #reading the chinese text from input file chomp($line); binmode(STDOUT, ":utf8"); print "$line\n"; #===> Here perl prints out some chinese text to the +command console, but different from what is given in input file my @hwnd=Win32::GuiTest::FindWindowLike(undef,$line); if($hwnd[0]) { print "window found\n"; } else { print "window not found\n"; } print OUTFILE $line; #==> Here perl prints out same chinese text as i +nput to the outfile

        Script 2

        use Encode; use Win32::GuiTest qw(FindWindowLike); $line="***Winow title in chinese**"; binmode(STDOUT, ":utf8"); print "$line\n"; #===> Here perl prints out some chinese text to the +command console, but different from what is given in input file my @hwnd=Win32::GuiTest::FindWindowLike(undef,$line); if($hwnd[0]) { print "window found\n"; } else { print "window not found\n"; }

        Script 1 gives me the output as "window not found" (though window is present)as the window title is read from the input text file. Script 2 gives me the proper output as window found, as the window title is hardcoded in the string.

        What am i doing wrong in script 1 while reading from unicode file.