Hi,
I am making a program that has to do some substitutions on Japanese two-byte chars. Basically, I need to substitute Japanese EUC spaces for ASCII spaces, and a few Japanese words for their English equiv.
Actually doing something like
s!JPCHARS!ascii chars!;
Works fine, but I don't want to put the Japanese chars in my script because some of the other people who will be working on it have dumb text-editors that can't open and save it correctly.
So, for example, if the Japnese space is 0x80 or something like that, I want to make my code something like
s!0x80! !;
I can't figure out how to find the hex code for a Japanese char though. I am trying to use hex or ord or pack or unpack, but I cant seem to get it to work. (probably because I don't even know which one I should be using)
For example, These are some little snippets I have found around different places I searched for an answer:
my $str1 = qq(あ);
my $str2 = qq(え);
print oct($str1); # gives me 0
print oct($str2); # gives me 0
print pack "CC", $str1; #gives me nothing
print pack "CC", $str2; #gives me nothing
print unpack "H2", $str1; #gives me e3
print unpack "H2", $str2; #gives me e3
printf("0x%02x\n", $str1); #gives me 0x00
printf("0x%02x\n", $str2); #gives me 0x00
The problem is that different Japanese chars are giving me the same value in the output, so I am obviously not using these correctly, but I can't find anything that helps me with regard to double bytes.
I realize I am way offtrack, so if anyone can point me in the right direction I would be most grateful!
Thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.