Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: getting Unicode character names from string

by csthflk (Novice)
on Oct 10, 2012 at 19:53 UTC ( #998304=note: print w/ replies, xml ) Need Help??


in reply to getting Unicode character names from string

I was able to hit on a solution to the first question with some help from Google.

This test code works well, although I confess that I don't fully yet understand the codepoint_hex method that gets me the code point I need:

while($testStr =~ m/(.)/g) { $string = pad(codepoint_hex($1)); print("$string\n"); print charnames::viacode($string) . "\n"; } sub codepoint_hex { if (my $char = shift) { return sprintf '%2.2x', unpack('U0U*', $char); } } sub pad { my $str = shift; while (length $str < 4) { $str = "0$str"; } return "0x$str"; }
Result:
0x03bb
GREEK SMALL LETTER LAMDA
0x03b1
GREEK SMALL LETTER ALPHA
0x1f78
GREEK SMALL LETTER OMICRON WITH VARIA
0x03c2
GREEK SMALL LETTER FINAL SIGMA


Jason


Comment on Re: getting Unicode character names from string
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998304]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-28 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls