Opening a Unicode file with Perl
Posted
by Jaco Pretorius
on Stack Overflow
See other posts from Stack Overflow
or by Jaco Pretorius
Published on 2010-03-17T11:18:31Z
Indexed on
2010/03/17
11:21 UTC
Read the original article
Hit count: 329
I'm using osql to run several sql scripts against a database and then I need to look at the results file to check if any errors occurred. The problem is that perl doesn't seem to like the fact that the results files are unicode.
I wrote a little test script to test it and the output comes out all warbled.
$file = shift;
open OUTPUT, $file or die "Can't open $file: $!\n";
while (<OUTPUT>) {
print $_;
if (/Invalid|invalid|Cannot|cannot/) {
push(@invalids, $file);
print "invalid file - $inputfile - schedule for retry\n";
last;
}
}
Any ideas? I've tried decoding using decode_utf8 but it makes no difference. I've also tried to set the encoding when opening the file.
I think the problem might be that osql puts the result file in UTF-16 format, but I'm not sure. When I open the file in textpad it just tells me 'Unicode'.
Edit: Using perl v5.8.8
© Stack Overflow or respective owner