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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.