snaporaz has asked for the wisdom of the Perl Monks concerning the following question:
I can't print out a proper new line. I tried 'pack', 'chr' (using the Unicode codes, not the "\r" "\n" names), and many other options. Using an hexadecimal editor I see I always end up printing out "0D 00 0D 0A 00" and not "0D 00 0A 00". It seems that no matter how I refer to the line feed character using the 000A code, a "0D" byte gets automatically stuck in front of it. Here is my (non-working) snippet:
Any idea? Thanks in advanceuse strict; my $infile=shift; my $outfile=shift; open IN, "<:encoding(UTF-16LE)", $infile or die; open OUT, ">:encoding(UTF-16LE)", $outfile or die; binmode OUT, ':utf8'; while (<IN>) { chomp; print OUT "$_"; #also tried: #print OUT "\x{0D}\x{0A}"; my $r=pack("U", 0x000D); my $n=pack("U", 0x000A); print OUT $r; print OUT $n; #also tried: #my $n=chr(0x000D); etc. } close(IN); close(OUT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: newline in unicode under windows
by iburrell (Chaplain) on Jul 12, 2004 at 20:16 UTC | |
by snaporaz (Acolyte) on Jul 12, 2004 at 22:15 UTC | |
by ysth (Canon) on Jul 13, 2004 at 01:56 UTC | |
|
Re: newline in unicode under windows
by PodMaster (Abbot) on Jul 12, 2004 at 19:44 UTC |