On Tue, 15 Apr 2003 01:26:32 +0900
SADAHIRO Tomoyuki <bqw10602(_at_)nifty(_dot_)com> wrote:
I tried to implement cat_decode() for the HZ encoding,
and make it coping with $chk.
#!perl
use encoding 'hz';
printf qq~~%04X\n~~, ord q :~{:C~}: ; # must print "597D\n"
__END__
In HZ, a tilde is encoded as two tileds, '~~'.
Then this codelet is equivalent to the following.
C<printf qq~%04X\n~, ord q :\x{597D}: ;>
Problem:
In HZ, a tilde *out of* a literal should be encoded as '~~', too.
e.g. C<$a = ~~ 1;> in HZ must be equivalent to C<$a = ~ 1;> in ASCII.
Sorry, this is one of problems.
(I need a cap of coffee..., or a napping)
Another problem on HZ concerns open() with :encoding(hz),
which is reported by a Perl user in Japan.
My rewriting decode() and encode() would fix it.
This is a test program.
#!perl
use strict;
use warnings;
use Encode;
my $code = "hz";
my $file = "$code.txt";
my $str1 = "~~Perl =~ s///;\n";
my $str2 = "\x{597D}" x 342; # 1024 + 2 bytes
my $str3 = "\tGB 21~~s\n\r32;\n";
my $all = "$str1$str2$str3";
unlink "./$file" if -f "./$file"; # XXX
open OUT, ">:encoding($code)", "./$file" or die $!;
print OUT $str1;
print OUT $str2;
print OUT $str3;
close (OUT);
open OUT, "<:encoding($code)", "./$file" or die $!;
my $in = join '', <OUT>;
print $in eq $all
? "ok" : "not ok", "\n";
__END__
SADAHIRO Tomoyuki