{
    "mode": "perldoc",
    "parameter": "Text::ParseWords",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Text%3A%3AParseWords/json",
    "generated": "2026-09-22T17:42:38Z",
    "synopsis": "use Text::ParseWords;\n@lists = nestedquotewords($delim, $keep, @lines);\n@words = quotewords($delim, $keep, @lines);\n@words = shellwords(@lines);\n@words = parseline($delim, $keep, $line);\n@words = oldshellwords(@lines); # DEPRECATED!",
    "sections": {
        "NAME": {
            "content": "Text::ParseWords - parse text into an array of tokens or array of arrays\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Text::ParseWords;\n@lists = nestedquotewords($delim, $keep, @lines);\n@words = quotewords($delim, $keep, @lines);\n@words = shellwords(@lines);\n@words = parseline($delim, $keep, $line);\n@words = oldshellwords(@lines); # DEPRECATED!\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The nestedquotewords() and quotewords() functions accept a delimiter (which can be a regular\nexpression) and a list of lines and then breaks those lines up into a list of words ignoring\ndelimiters that appear inside quotes. quotewords() returns all of the tokens in a single long\nlist, while nestedquotewords() returns a list of token lists corresponding to the elements of\n@lines. parseline() does tokenizing on a single string. The *quotewords() functions simply call",
            "subsections": [
                {
                    "name": "parse_line",
                    "content": "function call.\n\nThe $keep controls what happens with delimters and special characters:\n\ntrue\nIf true, then the tokens are split on the specified delimiter, but all other characters\n(including quotes and backslashes) are kept in the tokens.\n\nfalse\nIf $keep is false then the *quotewords() functions remove all quotes and backslashes that\nare not themselves backslash-escaped or inside of single quotes (i.e., quotewords() tries to\ninterpret these characters just like the Bourne shell). NB: these semantics are\nsignificantly different from the original version of this module shipped with Perl 5.000\nthrough 5.004.\n\n\"delimiters\"\nAs an additional feature, $keep may be the keyword \"delimiters\" which causes the functions\nto preserve the delimiters in each string as tokens in the token lists, in addition to\npreserving quote and backslash characters.\n"
                },
                {
                    "name": "shellwords",
                    "content": "whitespace as a delimiter-- similar to most Unix shells.\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "The sample program:\n\nuse Text::ParseWords;\n@words = quotewords('\\s+', 0, q{this   is \"a test\" of\\ quotewords \\\"for you});\n$i = 0;\nforeach (@words) {\nprint \"$i: <$>\\n\";\n$i++;\n}\n\nproduces:\n\n0: <this>\n1: <is>\n2: <a test>\n3: <of quotewords>\n4: <\"for>\n5: <you>\n\ndemonstrating:\n\n0   a simple word\n\n1   multiple spaces are skipped because of our $delim\n\n2   use of quotes to include a space in a word\n\n3   use of a backslash to include a space in a word\n\n4   use of a backslash to remove the special meaning of a double-quote\n\n5   another simple word (note the lack of effect of the backslashed double-quote)\n\nReplacing \"quotewords('\\s+', 0, q{this is...})\" with \"shellwords(q{this is...})\" is a simpler\nway to accomplish the same thing.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Text::CSV - for parsing CSV files\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "The original author is unknown, but presumably this evolved from \"shellwords.pl\" in Perl 4.\n\nMuch of the code for parseline() (including the primary regexp) came from Joerk Behrends\n<jbehrends@multimediaproduzenten.de>.\n\nExamples section and other documentation provided by John Heidemann <johnh@ISI.EDU>.\n\nHal Pomeranz <pomeranz@netcom.com> maintained this from 1994 through 1999, and did the first\nCPAN release.\n\nAlexandr Ciornii <alexchornyATgmail.com> maintained this from 2008 to 2015.\n\nMany other people have contributed, with special thanks due to Michael Schwern\n<schwern@envirolink.org> and Jeff Friedl <jfriedl@yahoo-inc.com>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This library is free software; you may redistribute and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Text::ParseWords - parse text into an array of tokens or array of arrays",
    "flags": [],
    "examples": [
        "The sample program:",
        "use Text::ParseWords;",
        "@words = quotewords('\\s+', 0, q{this   is \"a test\" of\\ quotewords \\\"for you});",
        "$i = 0;",
        "foreach (@words) {",
        "print \"$i: <$>\\n\";",
        "$i++;",
        "produces:",
        "0: <this>",
        "1: <is>",
        "2: <a test>",
        "3: <of quotewords>",
        "4: <\"for>",
        "5: <you>",
        "demonstrating:",
        "0   a simple word",
        "1   multiple spaces are skipped because of our $delim",
        "2   use of quotes to include a space in a word",
        "3   use of a backslash to include a space in a word",
        "4   use of a backslash to remove the special meaning of a double-quote",
        "5   another simple word (note the lack of effect of the backslashed double-quote)",
        "Replacing \"quotewords('\\s+', 0, q{this is...})\" with \"shellwords(q{this is...})\" is a simpler",
        "way to accomplish the same thing."
    ],
    "see_also": []
}