# unicode examples ################## # pragmas ################## # allows UTF-8 in source code use utf8; { # perl can now use Unicode in utf8 encoding # directly $myname = "シメオン"; print "Utf8:\t$myname\n"; # by specifying HEX unicode $myname = "\x{30B7}\x{30E1}\x{30AA}\x{30F3}"; # same thing print "Unicode:hex\t$myname\n"; # or by character name using the charnames module # and full unicode names, as in use charnames qw(:full); $myname ="\N{KATAKANA LETTER SI}\N{KATAKANA LETTER ME}\N{KATAKANA LETTER O}\N{KATAKANA LETTER N}"; print "Unicode:names\t$myname\n"; # or short unicode names in the form name:script use charnames qw(:short); $myname = "\N{katakana:si}\N{katakana:me}\N{katakana:o}\N{katakana:n}"; print "Or script:name\t$myname\n"; } # text operators Do The Right Thing print scalar(reverse $myname), "\n"; print "There are ", scalar split (//, $myname), " chars in $myname \n"; # #... and so on # same with text functions # Many unicode properties and block ranges are supported. # For all the supported properties, please see # lib/unicode/In # lib/unicode/Is and # lib/unicode/To directories #example: matching wide digits $text = "12345"; print "Saw numbers\n" if $text =~ /\p{IsDigit}/; # this does NOT work, though ;) print +("1" + "2"), "\n"; # prints 0; while \d and \p{IsDigit} match digit characters, # their representation is scalar representation, and not number. ################## # allow unicode names in text, and usage of unicode characters # as identifiers - as in Java ################## { # charnames seems to break when packages change. Why? $伝票=225; 伝票印刷($伝票, "\n"); sub 伝票印刷 {print @_;} package テスト; sub テスト { print "テスト\n";} package main; &テスト::テスト; # prints テスト }