{
    "content": [
        {
            "type": "text",
            "text": "# bytes (man)\n\n## NAME\n\nbytes - Perl pragma to expose the individual bytes of characters\n\n## SYNOPSIS\n\nuse bytes;\n... chr(...);       # or bytes::chr\n... index(...);     # or bytes::index\n... length(...);    # or bytes::length\n... ord(...);       # or bytes::ord\n... rindex(...);    # or bytes::rindex\n... substr(...);    # or bytes::substr\nno bytes;\n\n## DESCRIPTION\n\nPerl's characters are stored internally as sequences of one or more bytes.  This pragma\nallows for the examination of the individual bytes that together comprise a character.\n\n## Sections\n\n- **NAME**\n- **NOTICE**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **LIMITATIONS**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "bytes",
        "section": "",
        "mode": "man",
        "summary": "bytes - Perl pragma to expose the individual bytes of characters",
        "synopsis": "use bytes;\n... chr(...);       # or bytes::chr\n... index(...);     # or bytes::index\n... length(...);    # or bytes::length\n... ord(...);       # or bytes::ord\n... rindex(...);    # or bytes::rindex\n... substr(...);    # or bytes::substr\nno bytes;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTICE",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 48,
                "subsections": []
            },
            {
                "name": "LIMITATIONS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "bytes - Perl pragma to expose the individual bytes of characters\n",
                "subsections": []
            },
            "NOTICE": {
                "content": "Because the bytes pragma breaks encapsulation (i.e. it exposes the innards of how the perl\nexecutable currently happens to store a string), the byte values that result are in an\nunspecified encoding.\n\nUse of this module for anything other than debugging purposes is strongly discouraged.  If\nyou feel that the functions here within might be useful for your application, this possibly\nindicates a mismatch between your mental model of Perl Unicode and the current reality. In\nthat case, you may wish to read some of the perl Unicode documentation: perluniintro,\nperlunitut, perlunifaq and perlunicode.\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use bytes;\n... chr(...);       # or bytes::chr\n... index(...);     # or bytes::index\n... length(...);    # or bytes::length\n... ord(...);       # or bytes::ord\n... rindex(...);    # or bytes::rindex\n... substr(...);    # or bytes::substr\nno bytes;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Perl's characters are stored internally as sequences of one or more bytes.  This pragma\nallows for the examination of the individual bytes that together comprise a character.\n\nOriginally the pragma was designed for the loftier goal of helping incorporate Unicode into\nPerl, but the approach that used it was found to be defective, and the one remaining\nlegitimate use is for debugging when you need to non-destructively examine characters'\nindividual bytes.  Just insert this pragma temporarily, and remove it after the debugging is\nfinished.\n\nThe original usage can be accomplished by explicit (rather than this pragma's implicit)\nencoding using the Encode module:\n\nuse Encode qw/encode/;\n\nmy $utf8bytestring   = encode \"UTF8\",   $string;\nmy $latin1bytestring = encode \"Latin1\", $string;\n\nOr, if performance is needed and you are only interested in the UTF-8 representation:\n\nutf8::encode(my $utf8bytestring = $string);\n\n\"no bytes\" can be used to reverse the effect of \"use bytes\" within the current lexical scope.\n\nAs an example, when Perl sees \"$x = chr(400)\", it encodes the character in UTF-8 and stores\nit in $x. Then it is marked as character data, so, for instance, \"length $x\" returns 1.\nHowever, in the scope of the \"bytes\" pragma, $x is treated as a series of bytes - the bytes\nthat make up the UTF8 encoding - and \"length $x\" returns 2:\n\n$x = chr(400);\nprint \"Length is \", length $x, \"\\n\";     # \"Length is 1\"\nprintf \"Contents are %vd\\n\", $x;         # \"Contents are 400\"\n{\nuse bytes; # or \"require bytes; bytes::length()\"\nprint \"Length is \", length $x, \"\\n\"; # \"Length is 2\"\nprintf \"Contents are %vd\\n\", $x;     # \"Contents are 198.144 (on\n# ASCII platforms)\"\n}\n\n\"chr()\", \"ord()\", \"substr()\", \"index()\" and \"rindex()\" behave similarly.\n\nFor more on the implications, see perluniintro and perlunicode.\n\n\"bytes::length()\" is admittedly handy if you need to know the byte length of a Perl scalar.\nBut a more modern way is:\n\nuse Encode 'encode';\nlength(encode('UTF-8', $scalar))\n",
                "subsections": []
            },
            "LIMITATIONS": {
                "content": "\"bytes::substr()\" does not work as an llvvaalluuee(()).\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "perluniintro, perlunicode, utf8, Encode\n\n\n\nperl v5.34.0                                 2025-07-25                                 bytes(3perl)",
                "subsections": []
            }
        }
    }
}