{
    "mode": "perldoc",
    "parameter": "Text::Trim",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATrim/json",
    "generated": "2026-06-13T21:24:38Z",
    "synopsis": "use Text::Trim;\n$text = \"\\timportant data\\n\";\n$data = trim $text;\n# now $data contains \"important data\" and $text is unchanged\n# or:\ntrim $text; # work in-place, $text now contains \"important data\"\n@lines = <STDIN>;\nrtrim @lines; # remove trailing whitespace from all lines\n# Alternatively:\n@lines = rtrim <STDIN>;\n# Or even:\nwhile (<STDIN>) {\ntrim; # Change $ in place\n# ...\n}",
    "sections": {
        "NAME": {
            "content": "Text::Trim - remove leading and/or trailing whitespace from strings\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.04\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Text::Trim;\n\n$text = \"\\timportant data\\n\";\n$data = trim $text;\n# now $data contains \"important data\" and $text is unchanged\n\n# or:\ntrim $text; # work in-place, $text now contains \"important data\"\n\n@lines = <STDIN>;\nrtrim @lines; # remove trailing whitespace from all lines\n\n# Alternatively:\n@lines = rtrim <STDIN>;\n\n# Or even:\nwhile (<STDIN>) {\ntrim; # Change $ in place\n# ...\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides functions for removing leading and/or trailing whitespace from strings. It\nis basically a wrapper around some simple regexes with a flexible context-based interface.\n",
            "subsections": []
        },
        "EXPORTS": {
            "content": "All functions are exported by default.\n",
            "subsections": []
        },
        "CONTEXT HANDLING": {
            "content": "void context\nFunctions called in void context change their arguments in-place\n\ntrim(@strings); # All strings in @strings are trimmed in-place\n\nltrim($text);   # remove leading whitespace on $text\n\nrtrim;          # remove trailing whitespace on $\n\nNo changes are made to arguments in non-void contexts.\n\nlist context\nValues passed in are changed and returned without affecting the originals.\n\n@result = trim(@strings);    # @strings is unchanged\n\n@result = rtrim;             # @result contains rtrimmed $\n\n($result) = ltrim(@strings); # like $result = ltrim($strings[0]);\n\nscalar context\nAs list context but multiple arguments are stringified before being returned. Single arguments\nare unaffected. This means that under these circumstances, the value of $\" ($LISTSEPARATOR) is\nused to join the values. If you don't want this, make sure you only use single arguments when\ncalling in scalar context.\n\n@strings = (\"\\thello\\n\", \"\\tthere\\n\");\n$trimmed = trim(@strings);\n# $trimmed = \"hello there\"\n\nlocal $\" = ', ';\n$trimmed = trim(@strings);\n# Now $trimmed = \"hello, there\"\n\n$trimmed = rtrim;\n# $trimmed = $ minus trailing whitespace\n",
            "subsections": [
                {
                    "name": "Undefined values",
                    "content": "If any of the functions are called with undefined values, the behaviour is in general to pass\nthem through unchanged. When stringifying a list (calling in scalar context with multiple\narguments) undefined elements are excluded, but if all elements are undefined then the return\nvalue is also undefined.\n\n$foo = trim(undef);        # $foo is undefined\n$foo = trim(undef, undef); # $foo is undefined\n@foo = trim(undef, undef); # @foo contains 2 undefined values\ntrim(@foo)                 # @foo still contains 2 undefined values\n$foo = trim('', undef);    # $foo is ''\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "trim\nRemoves leading and trailing whitespace from all arguments, or $ if none are provided.\n\nrtrim\nLike \"trim()\" but removes only trailing (right) whitespace.\n\nltrim\nLike \"trim()\" but removes only leading (left) whitespace.\n",
            "subsections": []
        },
        "UNICODE": {
            "content": "Because this module is implemented using Perl regular expressions, it is capable of recognising\nand removing unicode whitespace characters (such as non-breaking spaces) from scalars with the\nutf8 flag on. See Encode for details about the utf8 flag.\n\nNote that this only applies in the case of perl versions after 5.8.0 or so.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Brent B. Powers' String::Strip performs a similar function in XS.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Matt Lawrence <mattlaw@cpan.org> - Original author and maintainer\n\nRyan Thompson <rjt@cpan.org> - Co-maintainer, miscellaneous fixes\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "<https://github.com/rjt-pl/Text-Trim/issues>: Bug reports and feature requests\n\n<https://github.com/rjt-pl/Text-Trim.git>: Source repository\n",
            "subsections": []
        },
        "ACKNOWLEDGEMENTS": {
            "content": "Terrence Brannon <metaperl@gmail.com> for bringing my attention to String::Strip and suggesting\ndocumentation changes.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\n<http://dev.perl.org/licenses/artistic.html>\n",
            "subsections": []
        }
    },
    "summary": "Text::Trim - remove leading and/or trailing whitespace from strings",
    "flags": [],
    "examples": [],
    "see_also": []
}