perl-unicode

zenkaku to ascii numbers

2004-01-27 00:30:08
I have (probably) a stupid question.

I'm trying to convert a set of Japanese "zenkaku" numbers to their ascii
equiavalents. I know I can use Jcode->tr(), but I'm using Perl 5.8.3,
and something tells me I should be able to do this natively in this
version of Perl.

Actually, I want to do slightly more than that. The end goal is to
convert the numbers into ascii, but just so that I don't have to go
through the hassle, I'd like to first change the string into utf8
(because I wouldn't know what encoding it's going to be until run time),
and then do the substitution:

   use Encode;
   use Encode::Guess;

   my $str  = "...."; # euc, sjis, jis or utf8?
   my $enc  = guess_encoding($str, qw(euc-jp shiftjis 7bit-jis utf8));
   # snip error handling
   my $utf8 = decode($enc->name, $str);

   # now substitute zenkaku numbers to ascii
   $utf8 =~ s/.../.../ # ???

So far all of my attempts are failing.
Can somebody please point me to the correct way to do this in recent Perls?

TIA
--d

<Prev in Thread] Current Thread [Next in Thread>
  • zenkaku to ascii numbers, Daisuke Maki <=