{
    "mode": "man",
    "parameter": "ENC2XS",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/ENC2XS/1/json",
    "generated": "2026-07-08T07:30:29Z",
    "synopsis": "enc2xs -[options]\nenc2xs -M ModName mapfiles...\nenc2xs -C",
    "sections": {
        "NAME": {
            "content": "enc2xs -- Perl Encode Module Generator\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "enc2xs -[options]\nenc2xs -M ModName mapfiles...\nenc2xs -C\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "enc2xs builds a Perl extension for use by Encode from either Unicode Character Mapping files\n(.ucm) or Tcl Encoding Files (.enc).  Besides being used internally during the build process\nof the Encode module, you can use enc2xs to add your own encoding to perl.  No knowledge of\nXS is necessary.\n",
            "subsections": [
                {
                    "name": "Quick Guide",
                    "content": "If you want to know as little about Perl as possible but need to add a new encoding, just\nread this chapter and forget the rest.\n\n0.  Have a .ucm file ready.  You can get it from somewhere or you can write your own from\nscratch or you can grab one from the Encode distribution and customize it.  For the UCM\nformat, see the next Chapter.  In the example below, I'll call my theoretical encoding\nmyascii, defined in my.ucm.  \"$\" is a shell prompt.\n\n$ ls -F\nmy.ucm\n\n1.  Issue a command as follows;\n\n$ enc2xs -M My my.ucm\ngenerating Makefile.PL\ngenerating My.pm\ngenerating README\ngenerating Changes\n\nNow take a look at your current directory.  It should look like this.\n\n$ ls -F\nMakefile.PL   My.pm         my.ucm        t/\n\nThe following files were created.\n\nMakefile.PL - MakeMaker script\nMy.pm       - Encode submodule\nt/My.t      - test file\n\n1.1.\nIf you want *.ucm installed together with the modules, do as follows;\n\n$ mkdir Encode\n$ mv *.ucm Encode\n$ enc2xs -M My Encode/*ucm\n\n2.  Edit the files generated.  You don't have to if you have no time AND no intention to give\nit to someone else.  But it is a good idea to edit the pod and to add more tests.\n\n3.  Now issue a command all Perl Mongers love:\n\n$ perl Makefile.PL\nWriting Makefile for Encode::My\n\n4.  Now all you have to do is make.\n\n$ make\ncp My.pm blib/lib/Encode/My.pm\n/usr/local/bin/perl /usr/local/bin/enc2xs -Q -O \\\n-o encodet.c -f encodet.fnm\nReading myascii (myascii)\nWriting compiled form\n128 bytes in string tables\n384 bytes (75%) saved spotting duplicates\n1 bytes (0.775%) saved using substrings\n....\nchmod 644 blib/arch/auto/Encode/My/My.bs\n$\n\nThe time it takes varies depending on how fast your machine is and how large your\nencoding is.  Unless you are working on something big like euc-tw, it won't take too\nlong.\n\n5.  You can \"make install\" already but you should test first.\n\n$ make test\nPERLDLNONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib \\\n-e 'use Test::Harness  qw(&runtests $verbose); \\\n$verbose=0; runtests @ARGV;' t/*.t\nt/My....ok\nAll tests successful.\nFiles=1, Tests=2,  0 wallclock secs\n( 0.09 cusr + 0.01 csys = 0.09 CPU)\n\n6.  If you are content with the test result, just \"make install\"\n\n7.  If you want to add your encoding to Encode's demand-loading list (so you don't have to\n\"use Encode::YourEncoding\"), run\n\nenc2xs -C\n\nto update Encode::ConfigLocal, a module that controls local settings.  After that, \"use\nEncode;\" is enough to load your encodings on demand.\n"
                },
                {
                    "name": "The Unicode Character Map",
                    "content": "Encode uses the Unicode Character Map (UCM) format for source character mappings.  This\nformat is used by IBM's ICU package and was adopted by Nick Ing-Simmons for use with the\nEncode module.  Since UCM is more flexible than Tcl's Encoding Map and far more user-\nfriendly, this is the recommended format for Encode now.\n\nA UCM file looks like this.\n\n#\n# Comments\n#\n<codesetname> \"US-ascii\" # Required\n<codesetalias> \"ascii\"   # Optional\n<mbcurmin> 1             # Required; usually 1\n<mbcurmax> 1             # Max. # of bytes/char\n<subchar> \\x3F             # Substitution char\n#\nCHARMAP\n<U0000> \\x00 |0 # <control>\n<U0001> \\x01 |0 # <control>\n<U0002> \\x02 |0 # <control>\n....\n<U007C> \\x7C |0 # VERTICAL LINE\n<U007D> \\x7D |0 # RIGHT CURLY BRACKET\n<U007E> \\x7E |0 # TILDE\n<U007F> \\x7F |0 # <control>\nEND CHARMAP\n\n•   Anything that follows \"#\" is treated as a comment.\n\n•   The header section continues until a line containing the word CHARMAP. This section has a\nform of <keyword> value, one pair per line.  Strings used as values must be quoted.\nBarewords are treated as numbers.  \\xXX represents a byte.\n\nMost of the keywords are self-explanatory. subchar means substitution character, not\nsubcharacter.  When you decode a Unicode sequence to this encoding but no matching\ncharacter is found, the byte sequence defined here will be used.  For most cases, the\nvalue here is \\x3F; in ASCII, this is a question mark.\n\n•   CHARMAP starts the character map section.  Each line has a form as follows:\n\n<UXXXX> \\xXX.. |0 # comment\n^     ^      ^\n|     |      +- Fallback flag\n|     +-------- Encoded byte sequence\n+-------------- Unicode Character ID in hex\n\nThe format is roughly the same as a header section except for the fallback flag: |\nfollowed by 0..3.   The meaning of the possible values is as follows:\n\n|0  Round trip safe.  A character decoded to Unicode encodes back to the same byte\nsequence.  Most characters have this flag.\n\n|1  Fallback for unicode -> encoding.  When seen, enc2xs adds this character for the\nencode map only.\n\n|2  Skip sub-char mapping should there be no code point.\n\n|3  Fallback for encoding -> unicode.  When seen, enc2xs adds this character for the\ndecode map only.\n\n•   And finally, END OF CHARMAP ends the section.\n\nWhen you are manually creating a UCM file, you should copy ascii.ucm or an existing encoding\nwhich is close to yours, rather than write your own from scratch.\n\nWhen you do so, make sure you leave at least U0000 to U0020 as is, unless your environment is\nEBCDIC.\n\nCAVEAT: not all features in UCM are implemented.  For example, icu:state is not used.\nBecause of that, you need to write a perl module if you want to support algorithmical\nencodings, notably the ISO-2022 series.  Such modules include Encode::JP::2022JP,\nEncode::KR::2022KR, and Encode::TW::HZ.\n"
                },
                {
                    "name": "Coping with duplicate mappings",
                    "content": "When you create a map, you SHOULD make your mappings round-trip safe.  That is,\n\"encode('your-encoding', decode('your-encoding', $data)) eq $data\" stands for all characters\nthat are marked as \"|0\".  Here is how to make sure:\n\n•   Sort your map in Unicode order.\n\n•   When you have a duplicate entry, mark either one with '|1' or '|3'.\n\n•   And make sure the '|1' or '|3' entry FOLLOWS the '|0' entry.\n\nHere is an example from big5-eten.\n\n<U2550> \\xF9\\xF9 |0\n<U2550> \\xA2\\xA4 |3\n\nInternally Encoding -> Unicode and Unicode -> Encoding Map looks like this;\n\nE to U               U to E\n--------------------------------------\n\\xF9\\xF9 => U2550    U2550 => \\xF9\\xF9\n\\xA2\\xA4 => U2550\n\nSo it is round-trip safe for \\xF9\\xF9.  But if the line above is upside down, here is what\nhappens.\n\nE to U               U to E\n--------------------------------------\n\\xA2\\xA4 => U2550    U2550 => \\xF9\\xF9\n(\\xF9\\xF9 => U2550 is now overwritten!)\n\nThe Encode package comes with ucmlint, a crude but sufficient utility to check the integrity\nof a UCM file.  Check under the Encode/bin directory for this.\n\nWhen in doubt, you can use ucmsort, yet another utility under Encode/bin directory.\n"
                }
            ]
        },
        "Bookmarks": {
            "content": "•   ICU Home Page <http://www.icu-project.org/>\n\n•   ICU Character Mapping Tables <http://site.icu-project.org/charts/charset>\n\n•   ICU:Conversion Data <http://www.icu-project.org/userguide/conversion-data.html>\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Encode, perlmod, perlpod\n\n\n\nperl v5.34.0                                 2026-06-23                                    ENC2XS(1)",
            "subsections": []
        }
    },
    "summary": "enc2xs -- Perl Encode Module Generator",
    "flags": [],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "not_found",
        "examples": []
    }
}