I would be very greatful if someone could give me a detailed description of the following regular expression:
s/([^\0-\x7F])/do {my $o = ord($1); sprintf("%c%c", 0xc0 | ($o >> 6), 0x80 | ($o & 0x3f)) }/ge
The above is the meat from a uri_escape_utf8 subroutine. I get the gist of what is going on; we're converting a utf-encoded string to its corresponding ASCII only uri representation. Furthermore,
First we capture any character whose hex representation does not fall within the range specified by the negative character class
[^\0-\x7F] (Which comprises the basic ASCII character set, I think).
Next every time we grab a legal character, we store the numeric value of our character in
$o, then we sprintf the conversion... But I don't know exactly what is going on in the sprintf statement...
I want to do something similar, convert all full and half width latin characters (0x0FF00-0x0FF5E) to their more common ASCII representations (0x00020-0x0007F), so any lucid explanation of the above code, or alternatively, how to directly solve my problem, will be greatly appreciated!!
P.S. I know I can do this with a hash of corresponding values, I'm hoping there is something shorter and more interesting.
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.