Deda has asked for the wisdom of the Perl Monks concerning the following question:

hello monks, I found some nodes on multibyte regexes, but none on printing. I have the following regex, that describes the Shift-JIS encoding (from http://www.perl.org/tpc/1998/User_Applications/Perl%20and%20Multiple-byte%20Char/perl2-lunde-paper.pdf)
$sjis= q{ # Shift-JIS encoding <[0-9A-F][0-9A-F][0-9A-F][0-9A-F]> + # CDPS Unicode tag | &\#x[0-9A-F][0-9A-F][0-9A-F][0-9A-F]; + # SGML Unicode tag | [\x00-\x7F] + # ASCII | [\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC] + # Two-byte range | [\xA0-\xDF] + # Half-width katakana };
My goal is to create a random string from this (or any other) regex. I got through the parsing part but am now stuck with the correct byte sequences. In e.g. \x83\xE3 and \x44\x81 are 2 correct 2-byte characters (from rule [\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]). The problem is: how do I print them - i can print byte by byte, but that does not give the correct results. To sum up: i have the correct byte sequence, i know which bytes "go together", i just don't know how to print the multibyte chars. Appreciate your aid, Deda.

Replies are listed 'Best First'.
Re: printing multibyte chars
by Roger (Parson) on Oct 03, 2003 at 14:29 UTC
    Go and have a look at the String::Multibyte module from CPAN. It has everything you need to print and manipulate the multibype strings.

    (You should always check CPAN first to see if there is already a module that does what you want.)
      (You're right. I should have learned by now, that everything i try to do has most likely been done in a CPAN module:).)