# this module shows how to define custom unicode characters # and use them in a perl program require 5.6.0; use utf8; package Custom; use charnames (); # to use charnames::hint_bits use bytes(); # for bytes constants # the import() subroutine # defines the custom character translator sub import { shift; $^H |= $charnames::hint_bits; $^H{charnames} = \&translator; } # the translator should care whether # we are running in byte or unicode mode, and # return appropriate values sub translator { if ($^H & $bytes::hint_bits) { # we are in byte mode return bytes_translator(@_); } else { # we are in unicode mode return utf8_translator(@_); } } sub bytes_translator { # return character if ASCII, die otherwise? "1"; } # see lib/charnames.pm for better translator examples sub utf8_translator { # return the matching Unicode character # should not eval or require for now return pack "U", hex "0xE001" if $_[0] =~ /custom_char_name/; die "Unkown character $_[0]"; } 1;