if the string "U+03C0" (or "0x03C0") is entered, then I want the string "0xCF80" to be printed (without quotes).
use Encode qw( encode_utf8 );
s{
^ U\+ ( [0-9a-fA-F]+ ) \z
}{
"0x" . uc(unpack("H*", encode_utf8(chr(hex($1)))))
}xe;
- chr(hex($1)) gets a character with the specified value.
- encode_utf8(...) encodes the code point.
- uc(unpack("H*", ...)) converts the byte sequence to hex.
If the string "0xCF80" is entered, then I want the string "U+03C0" (or "0x03C0") to be printed (without quotes).
use Encode qw( decode_utf8 );
s{
^ 0x ( (?: [0-9a-fA-F]{2} ){1,4} ) \z
}{
sprintf("U+%X", ord(decode_utf8(pack("H*", $1))))
}xe;
- pack("H*", $1) gets a string of bytes with the specified values.
- decode_utf8(...) decodes to a code point.
- sprintf("%X", ord(...)) converts the character to hex.
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.