View Full Version : jcode.pm string conversion
Yakisoba
03-10-2005, 05:30 AM
Im trying to write a simple script that will take multiple byte characters (zenkaku) and convert them into single byte characters (hankaku) using jcode.
Note: Im using a japanese keyboard and OS.
the documentation for jcode.pm is located at http://openlab.jp/Jcode/Jcode.html
The code that Im trying to write is very basic...
#!/Perl/bin/perl
#simple string converting program.
#this program will attemt to convert ZENKAKU to HENKAKU
#this code will be executed using command line
use CGI ':standard';
require ( "jcode.cgi" );
$zen = "A";
$han = "A";
#attmepts
#$convert = jcode::z2h_jis(\$zen);
#$convert = &jcode convert($zen, 'sjis');
print "This is zenkaku: $zen\n";
print "This is hankaku: $han\n";
print "This should be hankaku: $convert\n";
As you can see I havnt been able to master the converting part of it...
Im sure my answer is in the documentation I provided above, but I cant seem to make anything work.
any help would be greatly appreciated.
Thanks.
mlseim
03-10-2005, 03:27 PM
Which method are you using ...
Does your server have Jpost Module "jpost.pm" installed?
or are you using "jpost.pl" as an include file.
It looks like there are two different methods that
can be used.
You are right ... information on this is hard to find.
I have something for you to try:
1) download the attached file (jcode.txt),
2) rename it to "jcode.pl" and upload using ASCII, chmod 755.
(note, it's all small letters "jcode.pl")
3) copy and paste the script below, call it something like "jtest.pl".
and upload using ASCII, chmod to 755.
4) I have no way to test this thing, but you can experiment with it.
I also noticed your top line: #!/Perl/bin/perl
looks sort of strange to me. make sure it's correct for your server.
Here's the script called "jtest.pl":
#===================================================
#!/usr/local/bin/perl
#simple string converting program.
#this program will attemt to convert ZENKAKU to HENKAKU
#this code will be executed using command line
use CGI ':standard';
require "jcode.pl";
$zen = "A";
$ocode = "euc";
$icode = "sjis";
$han = jcode::convert(\$zen, $ocode, $icode, "z");
print "Content-type: text/html\n\n";
print "This is zenkaku: $zen <br><br>\n";
print "This is hankaku: $han\n";
#=================================================
.
Yakisoba
03-11-2005, 03:25 AM
Thanks for looking into this...english documentation on this matter is rare.
To answer your question regarding jpost.pm, I'm pretty sure I don't have that module installed.
I've been creating and testing my scripts on a laptop, which was purchased in Japan...Since I don't always have reliable access to the internet I'm using apache server to test.
I have jcode.pl installed and it appears to work (or do somthing)...unfortunatly when I try to do a simple conversion my output is a mess (full of strange characters)...at first I thought this might be hexidecimal values, but that was not the case.
As for my shebang line...yeah, I know its a little messed up. I had to create a new folder when I installed active perl on this Japanese computer to make the installation process a little easier. My ability to read (and understand) kanji is limited. This setup gives me easy access to perl, for now.
I ran the jtest.pl script you provided and got the following output:
This is zenkaku: A
This is hankaku: sjis
Looks like the value of $icode was assigned to $han.
...In my many attmepts to try and solve this conversion issue I also tried to use: (note: I had to change, require "jcode.pl"; to use Jcode; for this example)
$zen = "A";
$han = Jcode->new($zen)->z2h->jis;
the output for this is:
A
It appears "A" was converted, but what is all this crap surrounding it?!
jcode it driving me insane.
Any ideas are welcomed. I'm determined to make this jcode work.
I've heard I don't need to use this but the documetation may shed some light on Japanese character conversion: http://search.cpan.org/~hio/Unicode-Japanese-0.26/Japanese.pm
mlseim
03-11-2005, 02:11 PM
I think I read somewhere that if the $icode is not an actual
valid character that you are converting, it will return the
value of $icode (sjis) ... something like that.
If somehow, that "A" was an actual Zenkaku character,
it might return the correct conversion.
I think it can do a whole line also (not just one character).
It would also be nice if some Japanese coders used CodingForums ...
they could help you out with this.
Yakisoba
03-15-2005, 06:37 AM
I'm positive that the character(s) I used were zenkakku (multiple byte). I have the option to toggle between different character sets on this japanese keyboard.
Could it be possible I have installed Jcode improperly? I'm going to reinstall it and try again.
I've also installed Unicode::Japanese, although I had to do it manually. I can't seem to get ppm to work (it never connects).
mlseim
03-16-2005, 02:12 AM
I'm sort of at a loss now ...
I can't get into this any deeper without 1) knowing some Japanese,
2) some way to test things out. Sorry. I hope someone who knows
Japanese and Perl can stumble into this forum.
Yakisoba
03-17-2005, 08:51 AM
I think I may be getting close...
This seems to be converting characters (not the characters I want, but at least it converts), but I'm not exaclty sure what "$option" means. Figuring this out may be the final piece .
jcode::tr(\$line, $from, $to [, $option])
My code looks like:
jcode::tr(\$zen, '0-9A-Za-z', '0-9A-Za-z'); - notice $option is missing
If anyone could shed some light on what $option is that would be sweet...
Thank you mlseim for your input, it seems to be leading me in the right direction.
Yak
mlseim
03-17-2005, 02:32 PM
This is all I could find ...
# Optional parameter $option is used to specify optional
# conversion method. String "z" is for JIS X0201 KANA
# to X0208 KANA, and "h" is for reverse.
Yakisoba
03-22-2005, 02:27 AM
I was afraid of that...thats all I could find too.
looks like its back to the drawing board...
Thanks again for taking the time to look at this.
Yak
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.