Hi all,
I try to process a log file from ntbackup with perl. The file is unicode.
A piece of code to illustrate the problem:
#################
use strict;
use warnings;
use Encode;
use constant cut => '=' x 64;
my $time=localtime(time);
open IH, "<:encoding(UTF16)", "backup01.log" or die "Unable to open
backup01.log";
open OH, ">:encoding(UTF16)", "new.log" or die "Unable to open new.log";
print OH cut,"\n$time\n",cut,"\n"; # this fails
my $line;
while (<IH>)
{
print OH $_;
}
close IH;
close OH;
use constant cut => '=' x 64;
my $time=localtime(time);
open IH, "<:encoding(UTF16)", "backup01.log" or die "Unable to open
backup01.log";
open OH, ">:encoding(UTF16)", "new.log" or die "Unable to open new.log";
print OH cut,"\n$time\n",cut,"\n"; # this fails
my $line;
while (<IH>)
{
print OH $_;
}
close IH;
close OH;
#################
The problem is the "\n" character. The important part of the resulting file
in hex code is:
0000080: 003d 000d 0a00 5400 7500 6500 2000 4e00 .=....T.u.e. .N.
0000090: 6f00 7600 2000 3300 3000 2000 3100 3800 o.v. .3.0. .1.8.
00000a0: 3a00 3300 3000 3a00 3000 3700 2000 3200 :.3.0.:.0.7. .2.
00000b0: 3000 3000 3400 0d0a 003d 003d 003d 003d 0.0.4....=.=.=.=
It is to be seen, that the first newline is converted into
'00 0d 0a'. The right value should be '00 0d 00 0a'. It results in
a one byte left shifted date, the third line is readable (=====...),
the content of the original file is one byte shifted and unreadable.
Is this a mistake by me? What's wrong?
What can I do to write "\n" into such a file?
I use perl 5.8.4
Any tip or workaround is welcome.
Thanks
Torsten
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs