{
    "mode": "perldoc",
    "parameter": "Text::CSV_XS",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ACSV_XS/json",
    "generated": "2026-06-03T07:40:26Z",
    "synopsis": "# Functional interface\nuse Text::CSVXS qw( csv );\n# Read whole file in memory\nmy $aoa = csv (in => \"data.csv\");    # as array of array\nmy $aoh = csv (in => \"data.csv\",\nheaders => \"auto\");   # as array of hash\n# Write array of arrays as csv file\ncsv (in => $aoa, out => \"file.csv\", sepchar=> \";\");\n# Only show lines where \"code\" is odd\ncsv (in => \"data.csv\", filter => { code => sub { $ % 2 }});\n# Object interface\nuse Text::CSVXS;\nmy @rows;\n# Read/parse CSV\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<:encoding(utf8)\", \"test.csv\" or die \"test.csv: $!\";\nwhile (my $row = $csv->getline ($fh)) {\n$row->[2] =~ m/pattern/ or next; # 3rd field should match\npush @rows, $row;\n}\nclose $fh;\n# and write as CSV\nopen $fh, \">:encoding(utf8)\", \"new.csv\" or die \"new.csv: $!\";\n$csv->say ($fh, $) for @rows;\nclose $fh or die \"new.csv: $!\";",
    "sections": {
        "NAME": {
            "content": "Text::CSVXS - comma-separated values manipulation routines\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# Functional interface\nuse Text::CSVXS qw( csv );\n\n# Read whole file in memory\nmy $aoa = csv (in => \"data.csv\");    # as array of array\nmy $aoh = csv (in => \"data.csv\",\nheaders => \"auto\");   # as array of hash\n\n# Write array of arrays as csv file\ncsv (in => $aoa, out => \"file.csv\", sepchar=> \";\");\n\n# Only show lines where \"code\" is odd\ncsv (in => \"data.csv\", filter => { code => sub { $ % 2 }});\n\n\n# Object interface\nuse Text::CSVXS;\n\nmy @rows;\n# Read/parse CSV\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<:encoding(utf8)\", \"test.csv\" or die \"test.csv: $!\";\nwhile (my $row = $csv->getline ($fh)) {\n$row->[2] =~ m/pattern/ or next; # 3rd field should match\npush @rows, $row;\n}\nclose $fh;\n\n# and write as CSV\nopen $fh, \">:encoding(utf8)\", \"new.csv\" or die \"new.csv: $!\";\n$csv->say ($fh, $) for @rows;\nclose $fh or die \"new.csv: $!\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Text::CSVXS provides facilities for the composition and decomposition of comma-separated\nvalues. An instance of the Text::CSVXS class will combine fields into a \"CSV\" string and parse\na \"CSV\" string into fields.\n\nThe module accepts either strings or files as input and support the use of user-specified\ncharacters for delimiters, separators, and escapes.\n",
            "subsections": [
                {
                    "name": "Embedded newlines",
                    "content": "Important Note: The default behavior is to accept only ASCII characters in the range from 0x20\n(space) to 0x7E (tilde). This means that the fields can not contain newlines. If your data\ncontains newlines embedded in fields, or characters above 0x7E (tilde), or binary data, you\n*must* set \"binary => 1\" in the call to \"new\". To cover the widest range of parsing options, you\nwill always want to set binary.\n\nBut you still have the problem that you have to pass a correct line to the \"parse\" method, which\nis more complicated from the usual point of usage:\n\nmy $csv = Text::CSVXS->new ({ binary => 1, eol => $/ });\nwhile (<>) {           #  WRONG!\n$csv->parse ($);\nmy @fields = $csv->fields ();\n}\n\nthis will break, as the \"while\" might read broken lines: it does not care about the quoting. If\nyou need to support embedded newlines, the way to go is to not pass \"eol\" in the parser (it\naccepts \"\\n\", \"\\r\", and \"\\r\\n\" by default) and then\n\nmy $csv = Text::CSVXS->new ({ binary => 1 });\nopen my $fh, \"<\", $file or die \"$file: $!\";\nwhile (my $row = $csv->getline ($fh)) {\nmy @fields = @$row;\n}\n\nThe old(er) way of using global file handles is still supported\n\nwhile (my $row = $csv->getline (*ARGV)) { ... }\n"
                },
                {
                    "name": "Unicode",
                    "content": "Unicode is only tested to work with perl-5.8.2 and up.\n\nSee also \"BOM\".\n\nThe simplest way to ensure the correct encoding is used for in- and output is by either setting\nlayers on the filehandles, or setting the \"encoding\" argument for \"csv\".\n\nopen my $fh, \"<:encoding(UTF-8)\", \"in.csv\"  or die \"in.csv: $!\";\nor\nmy $aoa = csv (in => \"in.csv\",     encoding => \"UTF-8\");\n\nopen my $fh, \">:encoding(UTF-8)\", \"out.csv\" or die \"out.csv: $!\";\nor\ncsv (in => $aoa, out => \"out.csv\", encoding => \"UTF-8\");\n\nOn parsing (both for \"getline\" and \"parse\"), if the source is marked being UTF8, then all fields\nthat are marked binary will also be marked UTF8.\n\nOn combining (\"print\" and \"combine\"): if any of the combining fields was marked UTF8, the\nresulting string will be marked as UTF8. Note however that all fields *before* the first field\nmarked UTF8 and contained 8-bit characters that were not upgraded to UTF8, these will be \"bytes\"\nin the resulting string too, possibly causing unexpected errors. If you pass data of different\nencoding, or you don't know if there is different encoding, force it to be upgraded before you\npass them on:\n\n$csv->print ($fh, [ map { utf8::upgrade (my $x = $); $x } @data ]);\n\nFor complete control over encoding, please use Text::CSV::Encoded:\n\nuse Text::CSV::Encoded;\nmy $csv = Text::CSV::Encoded->new ({\nencodingin  => \"iso-8859-1\", # the encoding comes into   Perl\nencodingout => \"cp1252\",     # the encoding comes out of Perl\n});\n\n$csv = Text::CSV::Encoded->new ({ encoding  => \"utf8\" });\n# combine () and print () accept *literally* utf8 encoded data\n# parse () and getline () return *literally* utf8 encoded data\n\n$csv = Text::CSV::Encoded->new ({ encoding  => undef }); # default\n# combine () and print () accept UTF8 marked data\n# parse () and getline () return UTF8 marked data\n\nBOM\nBOM (or Byte Order Mark) handling is available only inside the \"header\" method. This method\nsupports the following encodings: \"utf-8\", \"utf-1\", \"utf-32be\", \"utf-32le\", \"utf-16be\",\n\"utf-16le\", \"utf-ebcdic\", \"scsu\", \"bocu-1\", and \"gb-18030\". See Wikipedia\n<https://en.wikipedia.org/wiki/Byteordermark>.\n\nIf a file has a BOM, the easiest way to deal with that is\n\nmy $aoh = csv (in => $file, detectbom => 1);\n\nAll records will be encoded based on the detected BOM.\n\nThis implies a call to the \"header\" method, which defaults to also set the \"columnnames\". So\nthis is not the same as\n\nmy $aoh = csv (in => $file, headers => \"auto\");\n\nwhich only reads the first record to set \"columnnames\" but ignores any meaning of possible\npresent BOM.\n"
                }
            ]
        },
        "SPECIFICATION": {
            "content": "While no formal specification for CSV exists, RFC 4180\n<https://datatracker.ietf.org/doc/html/rfc4180> (*1*) describes the common format and\nestablishes \"text/csv\" as the MIME type registered with the IANA. RFC 7111\n<https://datatracker.ietf.org/doc/html/rfc7111> (*2*) adds fragments to CSV.\n\nMany informal documents exist that describe the \"CSV\" format. \"How To: The Comma Separated Value\n(CSV) File Format\" <http://creativyst.com/Doc/Articles/CSV/CSV01.shtml> (*3*) provides an\noverview of the \"CSV\" format in the most widely used applications and explains how it can best\nbe used and supported.\n\n1) https://datatracker.ietf.org/doc/html/rfc4180\n2) https://datatracker.ietf.org/doc/html/rfc7111\n3) http://creativyst.com/Doc/Articles/CSV/CSV01.shtml\n\nThe basic rules are as follows:\n\nCSV is a delimited data format that has fields/columns separated by the comma character and\nrecords/rows separated by newlines. Fields that contain a special character (comma, newline, or\ndouble quote), must be enclosed in double quotes. However, if a line contains a single entry\nthat is the empty string, it may be enclosed in double quotes. If a field's value contains a\ndouble quote character it is escaped by placing another double quote character next to it. The\n\"CSV\" file format does not require a specific character encoding, byte order, or line terminator\nformat.\n\n* Each record is a single line ended by a line feed (ASCII/\"LF\"=0x0A) or a carriage return and\nline feed pair (ASCII/\"CRLF\"=\"0x0D 0x0A\"), however, line-breaks may be embedded.\n\n* Fields are separated by commas.\n\n* Allowable characters within a \"CSV\" field include 0x09 (\"TAB\") and the inclusive range of 0x20\n(space) through 0x7E (tilde). In binary mode all characters are accepted, at least in quoted\nfields.\n\n* A field within \"CSV\" must be surrounded by double-quotes to contain a separator character\n(comma).\n\nThough this is the most clear and restrictive definition, Text::CSVXS is way more liberal than\nthis, and allows extension:\n\n* Line termination by a single carriage return is accepted by default\n\n* The separation-, escape-, and escape- characters can be any ASCII character in the range from\n0x20 (space) to 0x7E (tilde). Characters outside this range may or may not work as expected.\nMultibyte characters, like UTF \"U+060C\" (ARABIC COMMA), \"U+FF0C\" (FULLWIDTH COMMA), \"U+241B\"\n(SYMBOL FOR ESCAPE), \"U+2424\" (SYMBOL FOR NEWLINE), \"U+FF02\" (FULLWIDTH QUOTATION MARK), and\n\"U+201C\" (LEFT DOUBLE QUOTATION MARK) (to give some examples of what might look promising)\nwork for newer versions of perl for \"sepchar\", and \"quotechar\" but not for \"escapechar\".\n\nIf you use perl-5.8.2 or higher these three attributes are utf8-decoded, to increase the\nlikelihood of success. This way \"U+00FE\" will be allowed as a quote character.\n\n* A field in \"CSV\" must be surrounded by double-quotes to make an embedded double-quote,\nrepresented by a pair of consecutive double-quotes, valid. In binary mode you may additionally\nuse the sequence \"\"0\" for representation of a NULL byte. Using 0x00 in binary mode is just as\nvalid.\n\n* Several violations of the above specification may be lifted by passing some options as\nattributes to the object constructor.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "version\n(Class method) Returns the current module version.\n\nnew\n(Class method) Returns a new instance of class Text::CSVXS. The attributes are described by the\n(optional) hash ref \"\\%attr\".\n\nmy $csv = Text::CSVXS->new ({ attributes ... });\n\nThe following attributes are available:\n\neol\nmy $csv = Text::CSVXS->new ({ eol => $/ });\n$csv->eol (undef);\nmy $eol = $csv->eol;\n\nThe end-of-line string to add to rows for \"print\" or the record separator for \"getline\".\n\nWhen not passed in a parser instance, the default behavior is to accept \"\\n\", \"\\r\", and \"\\r\\n\",\nso it is probably safer to not specify \"eol\" at all. Passing \"undef\" or the empty string behave\nthe same.\n\nWhen not passed in a generating instance, records are not terminated at all, so it is probably\nwise to pass something you expect. A safe choice for \"eol\" on output is either $/ or \"\\r\\n\".\n\nCommon values for \"eol\" are \"\\012\" (\"\\n\" or Line Feed), \"\\015\\012\" (\"\\r\\n\" or Carriage Return,\nLine Feed), and \"\\015\" (\"\\r\" or Carriage Return). The \"eol\" attribute cannot exceed 7 (ASCII)\ncharacters.\n\nIf both $/ and \"eol\" equal \"\\015\", parsing lines that end on only a Carriage Return without Line\nFeed, will be \"parse\"d correct.\n\nsepchar\nmy $csv = Text::CSVXS->new ({ sepchar => \";\" });\n$csv->sepchar (\";\");\nmy $c = $csv->sepchar;\n\nThe char used to separate fields, by default a comma. (\",\"). Limited to a single-byte character,\nusually in the range from 0x20 (space) to 0x7E (tilde). When longer sequences are required, use\n\"sep\".\n\nThe separation character can not be equal to the quote character or to the escape character.\n\nSee also \"CAVEATS\"\n\nsep\nmy $csv = Text::CSVXS->new ({ sep => \"\\N{FULLWIDTH COMMA}\" });\n$csv->sep (\";\");\nmy $sep = $csv->sep;\n\nThe chars used to separate fields, by default undefined. Limited to 8 bytes.\n\nWhen set, overrules \"sepchar\". If its length is one byte it acts as an alias to \"sepchar\".\n\nSee also \"CAVEATS\"\n\nquotechar\nmy $csv = Text::CSVXS->new ({ quotechar => \"'\" });\n$csv->quotechar (undef);\nmy $c = $csv->quotechar;\n\nThe character to quote fields containing blanks or binary data, by default the double quote\ncharacter (\"\"\"). A value of undef suppresses quote chars (for simple cases only). Limited to a\nsingle-byte character, usually in the range from 0x20 (space) to 0x7E (tilde). When longer\nsequences are required, use \"quote\".\n\n\"quotechar\" can not be equal to \"sepchar\".\n\nquote\nmy $csv = Text::CSVXS->new ({ quote => \"\\N{FULLWIDTH QUOTATION MARK}\" });\n$csv->quote (\"'\");\nmy $quote = $csv->quote;\n\nThe chars used to quote fields, by default undefined. Limited to 8 bytes.\n\nWhen set, overrules \"quotechar\". If its length is one byte it acts as an alias to \"quotechar\".\n\nThis method does not support \"undef\". Use \"quotechar\" to disable quotation.\n\nSee also \"CAVEATS\"\n\nescapechar\nmy $csv = Text::CSVXS->new ({ escapechar => \"\\\\\" });\n$csv->escapechar (\":\");\nmy $c = $csv->escapechar;\n\nThe character to escape certain characters inside quoted fields. This is limited to a\nsingle-byte character, usually in the range from 0x20 (space) to 0x7E (tilde).\n\nThe \"escapechar\" defaults to being the double-quote mark (\"\"\"). In other words the same as the\ndefault \"quotechar\". This means that doubling the quote mark in a field escapes it:\n\n\"foo\",\"bar\",\"Escape \"\"quote mark\"\" with two \"\"quote marks\"\"\",\"baz\"\n\nIf you change the \"quotechar\" without changing the \"escapechar\", the \"escapechar\" will still\nbe the double-quote (\"\"\"). If instead you want to escape the \"quotechar\" by doubling it you\nwill need to also change the \"escapechar\" to be the same as what you have changed the\n\"quotechar\" to.\n\nSetting \"escapechar\" to <undef> or \"\" will disable escaping completely and is greatly\ndiscouraged. This will also disable \"escapenull\".\n\nThe escape character can not be equal to the separation character.\n\nbinary\nmy $csv = Text::CSVXS->new ({ binary => 1 });\n$csv->binary (0);\nmy $f = $csv->binary;\n\nIf this attribute is 1, you may use binary characters in quoted fields, including line feeds,\ncarriage returns and \"NULL\" bytes. (The latter could be escaped as \"\"0\".) By default this\nfeature is off.\n\nIf a string is marked UTF8, \"binary\" will be turned on automatically when binary characters\nother than \"CR\" and \"NL\" are encountered. Note that a simple string like \"\\x{00a0}\" might still\nbe binary, but not marked UTF8, so setting \"{ binary => 1 }\" is still a wise option.\n\nstrict\nmy $csv = Text::CSVXS->new ({ strict => 1 });\n$csv->strict (0);\nmy $f = $csv->strict;\n\nIf this attribute is set to 1, any row that parses to a different number of fields than the\nprevious row will cause the parser to throw error 2014.\n\nskipemptyrows\nmy $csv = Text::CSVXS->new ({ skipemptyrows => 1 });\n$csv->skipemptyrows (0);\nmy $f = $csv->skipemptyrows;\n\nIf this attribute is set to 1, any row that has an \"eol\" immediately following the start of line\nwill be skipped. Default behavior is to return one single empty field.\n\nThis attribute is only used in parsing.\n\nformulahandling\nformula\nmy $csv = Text::CSVXS->new ({ formula => \"none\" });\n$csv->formula (\"none\");\nmy $f = $csv->formula;\n\nThis defines the behavior of fields containing *formulas*. As formulas are considered dangerous\nin spreadsheets, this attribute can define an optional action to be taken if a field starts with\nan equal sign (\"=\").\n\nFor purpose of code-readability, this can also be written as\n\nmy $csv = Text::CSVXS->new ({ formulahandling => \"none\" });\n$csv->formulahandling (\"none\");\nmy $f = $csv->formulahandling;\n\nPossible values for this attribute are\n\nnone\nTake no specific action. This is the default.\n\n$csv->formula (\"none\");\n\ndie\nCause the process to \"die\" whenever a leading \"=\" is encountered.\n\n$csv->formula (\"die\");\n\ncroak\nCause the process to \"croak\" whenever a leading \"=\" is encountered. (See Carp)\n\n$csv->formula (\"croak\");\n\ndiag\nReport position and content of the field whenever a leading \"=\" is found. The value of the\nfield is unchanged.\n\n$csv->formula (\"diag\");\n\nempty\nReplace the content of fields that start with a \"=\" with the empty string.\n\n$csv->formula (\"empty\");\n$csv->formula (\"\");\n\nundef\nReplace the content of fields that start with a \"=\" with \"undef\".\n\n$csv->formula (\"undef\");\n$csv->formula (undef);\n\na callback\nModify the content of fields that start with a \"=\" with the return-value of the callback. The\noriginal content of the field is available inside the callback as $;\n\n# Replace all formula's with 42\n$csv->formula (sub { 42; });\n\n# same as $csv->formula (\"empty\") but slower\n$csv->formula (sub { \"\" });\n\n# Allow =4+12\n$csv->formula (sub { s/^=(\\d+\\+\\d+)$/$1/eer });\n\n# Allow more complex calculations\n$csv->formula (sub { eval { s{^=([-+*/0-9()]+)$}{$1}ee }; $ });\n\nAll other values will give a warning and then fallback to \"diag\".\n\ndecodeutf8\nmy $csv = Text::CSVXS->new ({ decodeutf8 => 1 });\n$csv->decodeutf8 (0);\nmy $f = $csv->decodeutf8;\n\nThis attributes defaults to TRUE.\n\nWhile *parsing*, fields that are valid UTF-8, are automatically set to be UTF-8, so that\n\n$csv->parse (\"\\xC4\\xA8\\n\");\n\nresults in\n\nPV(\"\\304\\250\"\\0) [UTF8 \"\\x{128}\"]\n\nSometimes it might not be a desired action. To prevent those upgrades, set this attribute to\nfalse, and the result will be\n\nPV(\"\\304\\250\"\\0)\n\nautodiag\nmy $csv = Text::CSVXS->new ({ autodiag => 1 });\n$csv->autodiag (2);\nmy $l = $csv->autodiag;\n\nSet this attribute to a number between 1 and 9 causes \"errordiag\" to be automatically called in\nvoid context upon errors.\n\nIn case of error \"2012 - EOF\", this call will be void.\n\nIf \"autodiag\" is set to a numeric value greater than 1, it will \"die\" on errors instead of\n\"warn\". If set to anything unrecognized, it will be silently ignored.\n\nFuture extensions to this feature will include more reliable auto-detection of \"autodie\" being\nactive in the scope of which the error occurred which will increment the value of \"autodiag\"\nwith 1 the moment the error is detected.\n\ndiagverbose\nmy $csv = Text::CSVXS->new ({ diagverbose => 1 });\n$csv->diagverbose (2);\nmy $l = $csv->diagverbose;\n\nSet the verbosity of the output triggered by \"autodiag\". Currently only adds the current\ninput-record-number (if known) to the diagnostic output with an indication of the position of\nthe error.\n\nblankisundef\nmy $csv = Text::CSVXS->new ({ blankisundef => 1 });\n$csv->blankisundef (0);\nmy $f = $csv->blankisundef;\n\nUnder normal circumstances, \"CSV\" data makes no distinction between quoted- and unquoted empty\nfields. These both end up in an empty string field once read, thus\n\n1,\"\",,\" \",2\n\nis read as\n\n(\"1\", \"\", \"\", \" \", \"2\")\n\nWhen *writing* \"CSV\" files with either \"alwaysquote\" or \"quoteempty\" set, the unquoted *empty*\nfield is the result of an undefined value. To enable this distinction when *reading* \"CSV\" data,\nthe \"blankisundef\" attribute will cause unquoted empty fields to be set to \"undef\", causing\nthe above to be parsed as\n\n(\"1\", \"\", undef, \" \", \"2\")\n\nNote that this is specifically important when loading \"CSV\" fields into a database that allows\n\"NULL\" values, as the perl equivalent for \"NULL\" is \"undef\" in DBI land.\n\nemptyisundef\nmy $csv = Text::CSVXS->new ({ emptyisundef => 1 });\n$csv->emptyisundef (0);\nmy $f = $csv->emptyisundef;\n\nGoing one step further than \"blankisundef\", this attribute converts all empty fields to\n\"undef\", so\n\n1,\"\",,\" \",2\n\nis read as\n\n(1, undef, undef, \" \", 2)\n\nNote that this affects only fields that are originally empty, not fields that are empty after\nstripping allowed whitespace. YMMV.\n\nallowwhitespace\nmy $csv = Text::CSVXS->new ({ allowwhitespace => 1 });\n$csv->allowwhitespace (0);\nmy $f = $csv->allowwhitespace;\n\nWhen this option is set to true, the whitespace (\"TAB\"'s and \"SPACE\"'s) surrounding the\nseparation character is removed when parsing. If either \"TAB\" or \"SPACE\" is one of the three\ncharacters \"sepchar\", \"quotechar\", or \"escapechar\" it will not be considered whitespace.\n\nNow lines like:\n\n1 , \"foo\" , bar , 3 , zapp\n\nare parsed as valid \"CSV\", even though it violates the \"CSV\" specs.\n\nNote that all whitespace is stripped from both start and end of each field. That would make it\n*more* than a *feature* to enable parsing bad \"CSV\" lines, as\n\n1,   2.0,  3,   ape  , monkey\n\nwill now be parsed as\n\n(\"1\", \"2.0\", \"3\", \"ape\", \"monkey\")\n\neven if the original line was perfectly acceptable \"CSV\".\n\nallowloosequotes\nmy $csv = Text::CSVXS->new ({ allowloosequotes => 1 });\n$csv->allowloosequotes (0);\nmy $f = $csv->allowloosequotes;\n\nBy default, parsing unquoted fields containing \"quotechar\" characters like\n\n1,foo \"bar\" baz,42\n\nwould result in parse error 2034. Though it is still bad practice to allow this format, we\ncannot help the fact that some vendors make their applications spit out lines styled this way.\n\nIf there is really bad \"CSV\" data, like\n\n1,\"foo \"bar\" baz\",42\n\nor\n\n1,\"\"foo bar baz\"\",42\n\nthere is a way to get this data-line parsed and leave the quotes inside the quoted field as-is.\nThis can be achieved by setting \"allowloosequotes\" AND making sure that the \"escapechar\" is\n*not* equal to \"quotechar\".\n\nallowlooseescapes\nmy $csv = Text::CSVXS->new ({ allowlooseescapes => 1 });\n$csv->allowlooseescapes (0);\nmy $f = $csv->allowlooseescapes;\n\nParsing fields that have \"escapechar\" characters that escape characters that do not need to be\nescaped, like:\n\nmy $csv = Text::CSVXS->new ({ escapechar => \"\\\\\" });\n$csv->parse (qq{1,\"my bar\\'s\",baz,42});\n\nwould result in parse error 2025. Though it is bad practice to allow this format, this attribute\nenables you to treat all escape character sequences equal.\n\nallowunquotedescape\nmy $csv = Text::CSVXS->new ({ allowunquotedescape => 1 });\n$csv->allowunquotedescape (0);\nmy $f = $csv->allowunquotedescape;\n\nA backward compatibility issue where \"escapechar\" differs from \"quotechar\" prevents\n\"escapechar\" to be in the first position of a field. If \"quotechar\" is equal to the default\n\"\"\" and \"escapechar\" is set to \"\\\", this would be illegal:\n\n1,\\0,2\n\nSetting this attribute to 1 might help to overcome issues with backward compatibility and allow\nthis style.\n\nalwaysquote\nmy $csv = Text::CSVXS->new ({ alwaysquote => 1 });\n$csv->alwaysquote (0);\nmy $f = $csv->alwaysquote;\n\nBy default the generated fields are quoted only if they *need* to be. For example, if they\ncontain the separator character. If you set this attribute to 1 then *all* defined fields will\nbe quoted. (\"undef\" fields are not quoted, see \"blankisundef\"). This makes it quite often\neasier to handle exported data in external applications. (Poor creatures who are better to use\nText::CSVXS. :)\n\nquotespace\nmy $csv = Text::CSVXS->new ({ quotespace => 1 });\n$csv->quotespace (0);\nmy $f = $csv->quotespace;\n\nBy default, a space in a field would trigger quotation. As no rule exists this to be forced in\n\"CSV\", nor any for the opposite, the default is true for safety. You can exclude the space from\nthis trigger by setting this attribute to 0.\n\nquoteempty\nmy $csv = Text::CSVXS->new ({ quoteempty => 1 });\n$csv->quoteempty (0);\nmy $f = $csv->quoteempty;\n\nBy default the generated fields are quoted only if they *need* to be. An empty (defined) field\ndoes not need quotation. If you set this attribute to 1 then *empty* defined fields will be\nquoted. (\"undef\" fields are not quoted, see \"blankisundef\"). See also \"alwaysquote\".\n\nquotebinary\nmy $csv = Text::CSVXS->new ({ quotebinary => 1 });\n$csv->quotebinary (0);\nmy $f = $csv->quotebinary;\n\nBy default, all \"unsafe\" bytes inside a string cause the combined field to be quoted. By setting\nthis attribute to 0, you can disable that trigger for bytes >= 0x7F.\n\nescapenull\nmy $csv = Text::CSVXS->new ({ escapenull => 1 });\n$csv->escapenull (0);\nmy $f = $csv->escapenull;\n\nBy default, a \"NULL\" byte in a field would be escaped. This option enables you to treat the\n\"NULL\" byte as a simple binary character in binary mode (the \"{ binary => 1 }\" is set). The\ndefault is true. You can prevent \"NULL\" escapes by setting this attribute to 0.\n\nWhen the \"escapechar\" attribute is set to undefined, this attribute will be set to false.\n\nThe default setting will encode \"=\\x00=\" as\n\n\"=\"0=\"\n\nWith \"escapenull\" set, this will result in\n\n\"=\\x00=\"\n\nThe default when using the \"csv\" function is \"false\".\n\nFor backward compatibility reasons, the deprecated old name \"quotenull\" is still recognized.\n\nkeepmetainfo\nmy $csv = Text::CSVXS->new ({ keepmetainfo => 1 });\n$csv->keepmetainfo (0);\nmy $f = $csv->keepmetainfo;\n\nBy default, the parsing of input records is as simple and fast as possible. However, some\nparsing information - like quotation of the original field - is lost in that process. Setting\nthis flag to true enables retrieving that information after parsing with the methods\n\"metainfo\", \"isquoted\", and \"isbinary\" described below. Default is false for performance.\n\nIf you set this attribute to a value greater than 9, then you can control output quotation style\nlike it was used in the input of the the last parsed record (unless quotation was added because\nof other reasons).\n\nmy $csv = Text::CSVXS->new ({\nbinary         => 1,\nkeepmetainfo => 1,\nquotespace    => 0,\n});\n\nmy $row = $csv->parse (q{1,,\"\", ,\" \",f,\"g\",\"h\"\"h\",help,\"help\"});\n\n$csv->print (*STDOUT, \\@row);\n# 1,,, , ,f,g,\"h\"\"h\",help,help\n$csv->keepmetainfo (11);\n$csv->print (*STDOUT, \\@row);\n# 1,,\"\", ,\" \",f,\"g\",\"h\"\"h\",help,\"help\"\n\nundefstr\nmy $csv = Text::CSVXS->new ({ undefstr => \"\\\\N\" });\n$csv->undefstr (undef);\nmy $s = $csv->undefstr;\n\nThis attribute optionally defines the output of undefined fields. The value passed is not\nchanged at all, so if it needs quotation, the quotation needs to be included in the value of the\nattribute. Use with caution, as passing a value like \",\",,,,\"\"\" will for sure mess up your\noutput. The default for this attribute is \"undef\", meaning no special treatment.\n\nThis attribute is useful when exporting CSV data to be imported in custom loaders, like for\nMySQL, that recognize special sequences for \"NULL\" data.\n\nThis attribute has no meaning when parsing CSV data.\n\ncommentstr\nmy $csv = Text::CSVXS->new ({ commentstr => \"#\" });\n$csv->commentstr (undef);\nmy $s = $csv->commentstr;\n\nThis attribute optionally defines a string to be recognized as comment. If this attribute is\ndefined, all lines starting with this sequence will not be parsed as CSV but skipped as comment.\n\nThis attribute has no meaning when generating CSV.\n\nComment strings that start with any of the special characters/sequences are not supported (so it\ncannot start with any of \"sepchar\", \"quotechar\", \"escapechar\", \"sep\", \"quote\", or \"eol\").\n\nFor convenience, \"comment\" is an alias for \"commentstr\".\n\nverbatim\nmy $csv = Text::CSVXS->new ({ verbatim => 1 });\n$csv->verbatim (0);\nmy $f = $csv->verbatim;\n\nThis is a quite controversial attribute to set, but makes some hard things possible.\n\nThe rationale behind this attribute is to tell the parser that the normally special characters\nnewline (\"NL\") and Carriage Return (\"CR\") will not be special when this flag is set, and be\ndealt with as being ordinary binary characters. This will ease working with data with embedded\nnewlines.\n\nWhen \"verbatim\" is used with \"getline\", \"getline\" auto-\"chomp\"'s every line.\n\nImagine a file format like\n\nM^^Hans^Janssen^Klas 2\\n2A^Ja^11-06-2007#\\r\\n\n\nwhere, the line ending is a very specific \"#\\r\\n\", and the sepchar is a \"^\" (caret). None of\nthe fields is quoted, but embedded binary data is likely to be present. With the specific line\nending, this should not be too hard to detect.\n\nBy default, Text::CSVXS' parse function is instructed to only know about \"\\n\" and \"\\r\" to be\nlegal line endings, and so has to deal with the embedded newline as a real \"end-of-line\", so it\ncan scan the next line if binary is true, and the newline is inside a quoted field. With this\noption, we tell \"parse\" to parse the line as if \"\\n\" is just nothing more than a binary\ncharacter.\n\nFor \"parse\" this means that the parser has no more idea about line ending and \"getline\" \"chomp\"s\nline endings on reading.\n\ntypes\nA set of column types; the attribute is immediately passed to the \"types\" method.\n\ncallbacks\nSee the \"Callbacks\" section below.\n\naccessors\nTo sum it up,\n\n$csv = Text::CSVXS->new ();\n\nis equivalent to\n\n$csv = Text::CSVXS->new ({\neol                   => undef, # \\r, \\n, or \\r\\n\nsepchar              => ',',\nsep                   => undef,\nquotechar            => '\"',\nquote                 => undef,\nescapechar           => '\"',\nbinary                => 0,\ndecodeutf8           => 1,\nautodiag             => 0,\ndiagverbose          => 0,\nblankisundef        => 0,\nemptyisundef        => 0,\nallowwhitespace      => 0,\nallowloosequotes    => 0,\nallowlooseescapes   => 0,\nallowunquotedescape => 0,\nalwaysquote          => 0,\nquoteempty           => 0,\nquotespace           => 1,\nescapenull           => 1,\nquotebinary          => 1,\nkeepmetainfo        => 0,\nstrict                => 0,\nskipemptyrows       => 0,\nformula               => 0,\nverbatim              => 0,\nundefstr             => undef,\ncommentstr           => undef,\ntypes                 => undef,\ncallbacks             => undef,\n});\n\nFor all of the above mentioned flags, an accessor method is available where you can inquire the\ncurrent value, or change the value\n\nmy $quote = $csv->quotechar;\n$csv->binary (1);\n\nIt is not wise to change these settings halfway through writing \"CSV\" data to a stream. If\nhowever you want to create a new stream using the available \"CSV\" object, there is no harm in\nchanging them.\n\nIf the \"new\" constructor call fails, it returns \"undef\", and makes the fail reason available\nthrough the \"errordiag\" method.\n\n$csv = Text::CSVXS->new ({ ecschar => 1 }) or\ndie \"\".Text::CSVXS->errordiag ();\n\n\"errordiag\" will return a string like\n\n\"INI - Unknown attribute 'ecschar'\"\n\nknownattributes\n@attr = Text::CSVXS->knownattributes;\n@attr = Text::CSVXS::knownattributes;\n@attr = $csv->knownattributes;\n\nThis method will return an ordered list of all the supported attributes as described above. This\ncan be useful for knowing what attributes are valid in classes that use or extend Text::CSVXS.\n\nprint\n$status = $csv->print ($fh, $colref);\n\nSimilar to \"combine\" + \"string\" + \"print\", but much more efficient. It expects an array ref as\ninput (not an array!) and the resulting string is not really created, but immediately written to\nthe $fh object, typically an IO handle or any other object that offers a \"print\" method.\n\nFor performance reasons \"print\" does not create a result string, so all \"string\", \"status\",\n\"fields\", and \"errorinput\" methods will return undefined information after executing this\nmethod.\n\nIf $colref is \"undef\" (explicit, not through a variable argument) and \"bindcolumns\" was used to\nspecify fields to be printed, it is possible to make performance improvements, as otherwise data\nwould have to be copied as arguments to the method call:\n\n$csv->bindcolumns (\\($foo, $bar));\n$status = $csv->print ($fh, undef);\n\nA short benchmark\n\nmy @data = (\"aa\" .. \"zz\");\n$csv->bindcolumns (\\(@data));\n\n$csv->print ($fh, [ @data ]);   # 11800 recs/sec\n$csv->print ($fh,  \\@data  );   # 57600 recs/sec\n$csv->print ($fh,   undef  );   # 48500 recs/sec\n\nsay\n$status = $csv->say ($fh, $colref);\n\nLike \"print\", but \"eol\" defaults to $\\.\n\nprinthr\n$csv->printhr ($fh, $ref);\n\nProvides an easy way to print a $ref (as fetched with \"getlinehr\") provided the column names\nare set with \"columnnames\".\n\nIt is just a wrapper method with basic parameter checks over\n\n$csv->print ($fh, [ map { $ref->{$} } $csv->columnnames ]);\n\ncombine\n$status = $csv->combine (@fields);\n\nThis method constructs a \"CSV\" record from @fields, returning success or failure. Failure can\nresult from lack of arguments or an argument that contains an invalid character. Upon success,\n\"string\" can be called to retrieve the resultant \"CSV\" string. Upon failure, the value returned\nby \"string\" is undefined and \"errorinput\" could be called to retrieve the invalid argument.\n\nstring\n$line = $csv->string ();\n\nThis method returns the input to \"parse\" or the resultant \"CSV\" string of \"combine\", whichever\nwas called more recently.\n\ngetline\n$colref = $csv->getline ($fh);\n\nThis is the counterpart to \"print\", as \"parse\" is the counterpart to \"combine\": it parses a row\nfrom the $fh handle using the \"getline\" method associated with $fh and parses this row into an\narray ref. This array ref is returned by the function or \"undef\" for failure. When $fh does not\nsupport \"getline\", you are likely to hit errors.\n\nWhen fields are bound with \"bindcolumns\" the return value is a reference to an empty list.\n\nThe \"string\", \"fields\", and \"status\" methods are meaningless again.\n\ngetlineall\n$arrayref = $csv->getlineall ($fh);\n$arrayref = $csv->getlineall ($fh, $offset);\n$arrayref = $csv->getlineall ($fh, $offset, $length);\n\nThis will return a reference to a list of getline ($fh) results. In this call, \"keepmetainfo\"\nis disabled. If $offset is negative, as with \"splice\", only the last \"abs ($offset)\" records of\n$fh are taken into consideration.\n\nGiven a CSV file with 10 lines:\n\nlines call\n----- ---------------------------------------------------------\n0..9  $csv->getlineall ($fh)         # all\n0..9  $csv->getlineall ($fh,  0)     # all\n8..9  $csv->getlineall ($fh,  8)     # start at 8\n-     $csv->getlineall ($fh,  0,  0) # start at 0 first 0 rows\n0..4  $csv->getlineall ($fh,  0,  5) # start at 0 first 5 rows\n4..5  $csv->getlineall ($fh,  4,  2) # start at 4 first 2 rows\n8..9  $csv->getlineall ($fh, -2)     # last 2 rows\n6..7  $csv->getlineall ($fh, -4,  2) # first 2 of last  4 rows\n\ngetlinehr\nThe \"getlinehr\" and \"columnnames\" methods work together to allow you to have rows returned as\nhashrefs. You must call \"columnnames\" first to declare your column names.\n\n$csv->columnnames (qw( code name price description ));\n$hr = $csv->getlinehr ($fh);\nprint \"Price for $hr->{name} is $hr->{price} EUR\\n\";\n\n\"getlinehr\" will croak if called before \"columnnames\".\n\nNote that \"getlinehr\" creates a hashref for every row and will be much slower than the combined\nuse of \"bindcolumns\" and \"getline\" but still offering the same easy to use hashref inside the\nloop:\n\nmy @cols = @{$csv->getline ($fh)};\n$csv->columnnames (@cols);\nwhile (my $row = $csv->getlinehr ($fh)) {\nprint $row->{price};\n}\n\nCould easily be rewritten to the much faster:\n\nmy @cols = @{$csv->getline ($fh)};\nmy $row = {};\n$csv->bindcolumns (\\@{$row}{@cols});\nwhile ($csv->getline ($fh)) {\nprint $row->{price};\n}\n\nYour mileage may vary for the size of the data and the number of rows. With perl-5.14.2 the\ncomparison for a 100000 line file with 14 columns:\n\nRate hashrefs getlines\nhashrefs 1.00/s       --     -76%\ngetlines 4.15/s     313%       --\n\ngetlinehrall\n$arrayref = $csv->getlinehrall ($fh);\n$arrayref = $csv->getlinehrall ($fh, $offset);\n$arrayref = $csv->getlinehrall ($fh, $offset, $length);\n\nThis will return a reference to a list of getlinehr ($fh) results. In this call,\n\"keepmetainfo\" is disabled.\n\nparse\n$status = $csv->parse ($line);\n\nThis method decomposes a \"CSV\" string into fields, returning success or failure. Failure can\nresult from a lack of argument or the given \"CSV\" string is improperly formatted. Upon success,\n\"fields\" can be called to retrieve the decomposed fields. Upon failure calling \"fields\" will\nreturn undefined data and \"errorinput\" can be called to retrieve the invalid argument.\n\nYou may use the \"types\" method for setting column types. See \"types\"' description below.\n\nThe $line argument is supposed to be a simple scalar. Everything else is supposed to croak and\nset error 1500.\n\nfragment\nThis function tries to implement RFC7111 (URI Fragment Identifiers for the text/csv Media Type)\n- https://datatracker.ietf.org/doc/html/rfc7111\n\nmy $AoA = $csv->fragment ($fh, $spec);\n\nIn specifications, \"*\" is used to specify the *last* item, a dash (\"-\") to indicate a range. All\nindices are 1-based: the first row or column has index 1. Selections can be combined with the\nsemi-colon (\";\").\n\nWhen using this method in combination with \"columnnames\", the returned reference will point to\na list of hashes instead of a list of lists. A disjointed cell-based combined selection might\nreturn rows with different number of columns making the use of hashes unpredictable.\n\n$csv->columnnames (\"Name\", \"Age\");\nmy $AoH = $csv->fragment ($fh, \"col=3;8\");\n\nIf the \"afterparse\" callback is active, it is also called on every line parsed and skipped\nbefore the fragment.\n\nrow\nrow=4\nrow=5-7\nrow=6-*\nrow=1-2;4;6-*\n\ncol\ncol=2\ncol=1-3\ncol=4-*\ncol=1-2;4;7-*\n\ncell\nIn cell-based selection, the comma (\",\") is used to pair row and column\n\ncell=4,1\n\nThe range operator (\"-\") using \"cell\"s can be used to define top-left and bottom-right \"cell\"\nlocation\n\ncell=3,1-4,6\n\nThe \"*\" is only allowed in the second part of a pair\n\ncell=3,2-*,2    # row 3 till end, only column 2\ncell=3,2-3,*    # column 2 till end, only row 3\ncell=3,2-*,*    # strip row 1 and 2, and column 1\n\nCells and cell ranges may be combined with \";\", possibly resulting in rows with different\nnumbers of columns\n\ncell=1,1-2,2;3,3-4,4;1,4;4,1\n\nDisjointed selections will only return selected cells. The cells that are not specified will\nnot be included in the returned set, not even as \"undef\". As an example given a \"CSV\" like\n\n11,12,13,...19\n21,22,...28,29\n:            :\n91,...97,98,99\n\nwith \"cell=1,1-2,2;3,3-4,4;1,4;4,1\" will return:\n\n11,12,14\n21,22\n33,34\n41,43,44\n\nOverlapping cell-specs will return those cells only once, So \"cell=1,1-3,3;2,2-4,4;2,3;4,2\"\nwill return:\n\n11,12,13\n21,22,23,24\n31,32,33,34\n42,43,44\n\nRFC7111 <https://datatracker.ietf.org/doc/html/rfc7111> does not allow different types of specs\nto be combined (either \"row\" *or* \"col\" *or* \"cell\"). Passing an invalid fragment specification\nwill croak and set error 2013.\n\ncolumnnames\nSet the \"keys\" that will be used in the \"getlinehr\" calls. If no keys (column names) are\npassed, it will return the current setting as a list.\n\n\"columnnames\" accepts a list of scalars (the column names) or a single arrayref, so you can\npass the return value from \"getline\" too:\n\n$csv->columnnames ($csv->getline ($fh));\n\n\"columnnames\" does no checking on duplicates at all, which might lead to unexpected results.\nUndefined entries will be replaced with the string \"\\cAUNDEF\\cA\", so\n\n$csv->columnnames (undef, \"\", \"name\", \"name\");\n$hr = $csv->getlinehr ($fh);\n\nwill set \"$hr->{\"\\cAUNDEF\\cA\"}\" to the 1st field, \"$hr->{\"\"}\" to the 2nd field, and\n\"$hr->{name}\" to the 4th field, discarding the 3rd field.\n\n\"columnnames\" croaks on invalid arguments.\n\nheader\nThis method does NOT work in perl-5.6.x\n\nParse the CSV header and set \"sep\", columnnames and encoding.\n\nmy @hdr = $csv->header ($fh);\n$csv->header ($fh, { sepset => [ \";\", \",\", \"|\", \"\\t\" ] });\n$csv->header ($fh, { detectbom => 1, mungecolumnnames => \"lc\" });\n\nThe first argument should be a file handle.\n\nThis method resets some object properties, as it is supposed to be invoked only once per file or\nstream. It will leave attributes \"columnnames\" and \"boundcolumns\" alone if setting column\nnames is disabled. Reading headers on previously process objects might fail on perl-5.8.0 and\nolder.\n\nAssuming that the file opened for parsing has a header, and the header does not contain\nproblematic characters like embedded newlines, read the first line from the open handle then\nauto-detect whether the header separates the column names with a character from the allowed\nseparator list.\n\nIf any of the allowed separators matches, and none of the *other* allowed separators match, set\n\"sep\" to that separator for the current CSVXS instance and use it to parse the first line, map\nthose to lowercase, and use that to set the instance \"columnnames\":\n\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<\", \"file.csv\";\nbinmode $fh; # for Windows\n$csv->header ($fh);\nwhile (my $row = $csv->getlinehr ($fh)) {\n...\n}\n\nIf the header is empty, contains more than one unique separator out of the allowed set, contains\nempty fields, or contains identical fields (after folding), it will croak with error 1010, 1011,\n1012, or 1013 respectively.\n\nIf the header contains embedded newlines or is not valid CSV in any other way, this method will\ncroak and leave the parse error untouched.\n\nA successful call to \"header\" will always set the \"sep\" of the $csv object. This behavior can\nnot be disabled.\n\nreturn value\nOn error this method will croak.\n\nIn list context, the headers will be returned whether they are used to set \"columnnames\" or\nnot.\n\nIn scalar context, the instance itself is returned. Note: the values as found in the header will\neffectively be lost if \"setcolumnnames\" is false.\n\nOptions\nsepset\n$csv->header ($fh, { sepset => [ \";\", \",\", \"|\", \"\\t\" ] });\n\nThe list of legal separators defaults to \"[ \";\", \",\" ]\" and can be changed by this option. As\nthis is probably the most often used option, it can be passed on its own as an unnamed\nargument:\n\n$csv->header ($fh, [ \";\", \",\", \"|\", \"\\t\", \"::\", \"\\x{2063}\" ]);\n\nMulti-byte sequences are allowed, both multi-character and Unicode. See \"sep\".\n\ndetectbom\n$csv->header ($fh, { detectbom => 1 });\n\nThe default behavior is to detect if the header line starts with a BOM. If the header has a\nBOM, use that to set the encoding of $fh. This default behavior can be disabled by passing a\nfalse value to \"detectbom\".\n\nSupported encodings from BOM are: UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, and UTF-32LE. BOM also\nsupports UTF-1, UTF-EBCDIC, SCSU, BOCU-1, and GB-18030 but Encode does not (yet). UTF-7 is not\nsupported.\n\nIf a supported BOM was detected as start of the stream, it is stored in the object attribute\n\"ENCODING\".\n\nmy $enc = $csv->{ENCODING};\n\nThe encoding is used with \"binmode\" on $fh.\n\nIf the handle was opened in a (correct) encoding, this method will not alter the encoding, as\nit checks the leading bytes of the first line. In case the stream starts with a decoded BOM\n(\"U+FEFF\"), \"{ENCODING}\" will be \"\" (empty) instead of the default \"undef\".\n\nmungecolumnnames\nThis option offers the means to modify the column names into something that is most useful to\nthe application. The default is to map all column names to lower case.\n\n$csv->header ($fh, { mungecolumnnames => \"lc\" });\n\nThe following values are available:\n\nlc     - lower case\nuc     - upper case\ndb     - valid DB field names\nnone   - do not change\n\\%hash - supply a mapping\n\\&cb   - supply a callback\n\nLower case\n$csv->header ($fh, { mungecolumnnames => \"lc\" });\n\nThe header is changed to all lower-case\n\n$ = lc;\n\nUpper case\n$csv->header ($fh, { mungecolumnnames => \"uc\" });\n\nThe header is changed to all upper-case\n\n$ = uc;\n\nLiteral\n$csv->header ($fh, { mungecolumnnames => \"none\" });\n\nHash\n$csv->header ($fh, { mungecolumnnames => { foo => \"sombrero\" });\n\nif a value does not exist, the original value is used unchanged\n\nDatabase\n$csv->header ($fh, { mungecolumnnames => \"db\" });\n\n- lower-case\n\n- all sequences of non-word characters are replaced with an underscore\n\n- all leading underscores are removed\n\n$ = lc (s/\\W+//gr =~ s/^+//r);\n\nCallback\n$csv->header ($fh, { mungecolumnnames => sub { fc } });\n$csv->header ($fh, { mungecolumnnames => sub { \"column\".$col++ } });\n$csv->header ($fh, { mungecolumnnames => sub { lc (s/\\W+//gr) } });\n\nAs this callback is called in a \"map\", you can use $ directly.\n\nsetcolumnnames\n$csv->header ($fh, { setcolumnnames => 1 });\n\nThe default is to set the instances column names using \"columnnames\" if the method is\nsuccessful, so subsequent calls to \"getlinehr\" can return a hash. Disable setting the header\ncan be forced by using a false value for this option.\n\nAs described in \"return value\" above, content is lost in scalar context.\n\nValidation\nWhen receiving CSV files from external sources, this method can be used to protect against\nchanges in the layout by restricting to known headers (and typos in the header fields).\n\nmy %known = (\n\"record key\" => \"crec\",\n\"rec id\"     => \"crec\",\n\"idrec\"     => \"crec\",\n\"kode\"       => \"code\",\n\"code\"       => \"code\",\n\"vaule\"      => \"value\",\n\"value\"      => \"value\",\n);\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<\", $source or die \"$source: $!\";\n$csv->header ($fh, { mungecolumnnames => sub {\ns/\\s+$//;\ns/^\\s+//;\n$known{lc $} or die \"Unknown column '$' in $source\";\n}});\nwhile (my $row = $csv->getlinehr ($fh)) {\nsay join \"\\t\", $row->{crec}, $row->{code}, $row->{value};\n}\n\nbindcolumns\nTakes a list of scalar references to be used for output with \"print\" or to store in the fields\nfetched by \"getline\". When you do not pass enough references to store the fetched fields in,\n\"getline\" will fail with error 3006. If you pass more than there are fields to return, the\ncontent of the remaining references is left untouched.\n\n$csv->bindcolumns (\\$code, \\$name, \\$price, \\$description);\nwhile ($csv->getline ($fh)) {\nprint \"The price of a $name is \\x{20ac} $price\\n\";\n}\n\nTo reset or clear all column binding, call \"bindcolumns\" with the single argument \"undef\". This\nwill also clear column names.\n\n$csv->bindcolumns (undef);\n\nIf no arguments are passed at all, \"bindcolumns\" will return the list of current bindings or\n\"undef\" if no binds are active.\n\nNote that in parsing with \"bindcolumns\", the fields are set on the fly. That implies that if\nthe third field of a row causes an error (or this row has just two fields where the previous row\nhad more), the first two fields already have been assigned the values of the current row, while\nthe rest of the fields will still hold the values of the previous row. If you want the parser to\nfail in these cases, use the \"strict\" attribute.\n\neof\n$eof = $csv->eof ();\n\nIf \"parse\" or \"getline\" was used with an IO stream, this method will return true (1) if the last\ncall hit end of file, otherwise it will return false (''). This is useful to see the difference\nbetween a failure and end of file.\n\nNote that if the parsing of the last line caused an error, \"eof\" is still true. That means that\nif you are *not* using \"autodiag\", an idiom like\n\nwhile (my $row = $csv->getline ($fh)) {\n# ...\n}\n$csv->eof or $csv->errordiag;\n\nwill *not* report the error. You would have to change that to\n\nwhile (my $row = $csv->getline ($fh)) {\n# ...\n}\n+$csv->errordiag and $csv->errordiag;\n\ntypes\n$csv->types (\\@tref);\n\nThis method is used to force that (all) columns are of a given type. For example, if you have an\ninteger column, two columns with doubles and a string column, then you might do a\n\n$csv->types ([Text::CSVXS::IV (),\nText::CSVXS::NV (),\nText::CSVXS::NV (),\nText::CSVXS::PV ()]);\n\nColumn types are used only for *decoding* columns while parsing, in other words by the \"parse\"\nand \"getline\" methods.\n\nYou can unset column types by doing a\n\n$csv->types (undef);\n\nor fetch the current type settings with\n\n$types = $csv->types ();\n\nIV  Set field type to integer.\n\nNV  Set field type to numeric/float.\n\nPV  Set field type to string.\n\nfields\n@columns = $csv->fields ();\n\nThis method returns the input to \"combine\" or the resultant decomposed fields of a successful\n\"parse\", whichever was called more recently.\n\nNote that the return value is undefined after using \"getline\", which does not fill the data\nstructures returned by \"parse\".\n\nmetainfo\n@flags = $csv->metainfo ();\n\nThis method returns the \"flags\" of the input to \"combine\" or the flags of the resultant\ndecomposed fields of \"parse\", whichever was called more recently.\n\nFor each field, a metainfo field will hold flags that inform something about the field returned\nby the \"fields\" method or passed to the \"combine\" method. The flags are bit-wise-\"or\"'d like:\n\n\" \"0x0001\nThe field was quoted.\n\n\" \"0x0002\nThe field was binary.\n\nSee the \"is*\" methods below.\n\nisquoted\nmy $quoted = $csv->isquoted ($columnidx);\n\nwhere $columnidx is the (zero-based) index of the column in the last result of \"parse\".\n\nThis returns a true value if the data in the indicated column was enclosed in \"quotechar\"\nquotes. This might be important for fields where content \",20070108,\" is to be treated as a\nnumeric value, and where \",\"20070108\",\" is explicitly marked as character string data.\n\nThis method is only valid when \"keepmetainfo\" is set to a true value.\n\nisbinary\nmy $binary = $csv->isbinary ($columnidx);\n\nwhere $columnidx is the (zero-based) index of the column in the last result of \"parse\".\n\nThis returns a true value if the data in the indicated column contained any byte in the range\n\"[\\x00-\\x08,\\x10-\\x1F,\\x7F-\\xFF]\".\n\nThis method is only valid when \"keepmetainfo\" is set to a true value.\n\nismissing\nmy $missing = $csv->ismissing ($columnidx);\n\nwhere $columnidx is the (zero-based) index of the column in the last result of \"getlinehr\".\n\n$csv->keepmetainfo (1);\nwhile (my $hr = $csv->getlinehr ($fh)) {\n$csv->ismissing (0) and next; # This was an empty line\n}\n\nWhen using \"getlinehr\", it is impossible to tell if the parsed fields are \"undef\" because they\nwhere not filled in the \"CSV\" stream or because they were not read at all, as all the fields\ndefined by \"columnnames\" are set in the hash-ref. If you still need to know if all fields in\neach row are provided, you should enable \"keepmetainfo\" so you can check the flags.\n\nIf \"keepmetainfo\" is \"false\", \"ismissing\" will always return \"undef\", regardless of\n$columnidx being valid or not. If this attribute is \"true\" it will return either 0 (the field\nis present) or 1 (the field is missing).\n\nA special case is the empty line. If the line is completely empty - after dealing with the flags\n- this is still a valid CSV line: it is a record of just one single empty field. However, if\n\"keepmetainfo\" is set, invoking \"ismissing\" with index 0 will now return true.\n\nstatus\n$status = $csv->status ();\n\nThis method returns the status of the last invoked \"combine\" or \"parse\" call. Status is success\n(true: 1) or failure (false: \"undef\" or 0).\n\nNote that as this only keeps track of the status of above mentioned methods, you are probably\nlooking for \"errordiag\" instead.\n\nerrorinput\n$badargument = $csv->errorinput ();\n\nThis method returns the erroneous argument (if it exists) of \"combine\" or \"parse\", whichever was\ncalled more recently. If the last invocation was successful, \"errorinput\" will return \"undef\".\n\nDepending on the type of error, it *might* also hold the data for the last error-input of\n\"getline\".\n\nerrordiag\nText::CSVXS->errordiag ();\n$csv->errordiag ();\n$errorcode               = 0  + $csv->errordiag ();\n$errorstr                = \"\" . $csv->errordiag ();\n($cde, $str, $pos, $rec, $fld) = $csv->errordiag ();\n\nIf (and only if) an error occurred, this function returns the diagnostics of that error.\n\nIf called in void context, this will print the internal error code and the associated error\nmessage to STDERR.\n\nIf called in list context, this will return the error code and the error message in that order.\nIf the last error was from parsing, the rest of the values returned are a best guess at the\nlocation within the line that was being parsed. Their values are 1-based. The position currently\nis index of the byte at which the parsing failed in the current record. It might change to be\nthe index of the current character in a later release. The records is the index of the record\nparsed by the csv instance. The field number is the index of the field the parser thinks it is\ncurrently trying to parse. See examples/csv-check for how this can be used.\n\nIf called in scalar context, it will return the diagnostics in a single scalar, a-la $!. It will\ncontain the error code in numeric context, and the diagnostics message in string context.\n\nWhen called as a class method or a direct function call, the diagnostics are that of the last\n\"new\" call.\n\nrecordnumber\n$recno = $csv->recordnumber ();\n\nReturns the records parsed by this csv instance. This value should be more accurate than $. when\nembedded newlines come in play. Records written by this instance are not counted.\n",
            "subsections": [
                {
                    "name": "SetDiag",
                    "content": "$csv->SetDiag (0);\n\nUse to reset the diagnostics if you are dealing with errors.\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "csv\nThis function is not exported by default and should be explicitly requested:\n\nuse Text::CSVXS qw( csv );\n\nThis is a high-level function that aims at simple (user) interfaces. This can be used to\nread/parse a \"CSV\" file or stream (the default behavior) or to produce a file or write to a\nstream (define the \"out\" attribute). It returns an array- or hash-reference on parsing (or\n\"undef\" on fail) or the numeric value of \"errordiag\" on writing. When this function fails you\ncan get to the error using the class call to \"errordiag\"\n\nmy $aoa = csv (in => \"test.csv\") or\ndie Text::CSVXS->errordiag;\n\nThis function takes the arguments as key-value pairs. This can be passed as a list or as an\nanonymous hash:\n\nmy $aoa = csv (  in => \"test.csv\", sepchar => \";\");\nmy $aoh = csv ({ in => $fh, headers => \"auto\" });\n\nThe arguments passed consist of two parts: the arguments to \"csv\" itself and the optional\nattributes to the \"CSV\" object used inside the function as enumerated and explained in \"new\".\n\nIf not overridden, the default option used for CSV is\n\nautodiag   => 1\nescapenull => 0\n\nThe option that is always set and cannot be altered is\n\nbinary      => 1\n\nAs this function will likely be used in one-liners, it allows \"quote\" to be abbreviated as\n\"quo\", and \"escapechar\" to be abbreviated as \"esc\" or \"escape\".\n\nAlternative invocations:\n\nmy $aoa = Text::CSVXS::csv (in => \"file.csv\");\n\nmy $csv = Text::CSVXS->new ();\nmy $aoa = $csv->csv (in => \"file.csv\");\n\nIn the latter case, the object attributes are used from the existing object and the attribute\narguments in the function call are ignored:\n\nmy $csv = Text::CSVXS->new ({ sepchar => \";\" });\nmy $aoh = $csv->csv (in => \"file.csv\", bom => 1);\n\nwill parse using \";\" as \"sepchar\", not \",\".\n\nin\nUsed to specify the source. \"in\" can be a file name (e.g. \"file.csv\"), which will be opened for\nreading and closed when finished, a file handle (e.g. $fh or \"FH\"), a reference to a glob (e.g.\n\"\\*ARGV\"), the glob itself (e.g. *STDIN), or a reference to a scalar (e.g. \"\\q{1,2,\"csv\"}\").\n\nWhen used with \"out\", \"in\" should be a reference to a CSV structure (AoA or AoH) or a CODE-ref\nthat returns an array-reference or a hash-reference. The code-ref will be invoked with no\narguments.\n\nmy $aoa = csv (in => \"file.csv\");\n\nopen my $fh, \"<\", \"file.csv\";\nmy $aoa = csv (in => $fh);\n\nmy $csv = [ [qw( Foo Bar )], [ 1, 2 ], [ 2, 3 ]];\nmy $err = csv (in => $csv, out => \"file.csv\");\n\nIf called in void context without the \"out\" attribute, the resulting ref will be used as input\nto a subsequent call to csv:\n\ncsv (in => \"file.csv\", filter => { 2 => sub { length > 2 }})\n\nwill be a shortcut to\n\ncsv (in => csv (in => \"file.csv\", filter => { 2 => sub { length > 2 }}))\n\nwhere, in the absence of the \"out\" attribute, this is a shortcut to\n\ncsv (in  => csv (in => \"file.csv\", filter => { 2 => sub { length > 2 }}),\nout => *STDOUT)\n\nout\ncsv (in => $aoa, out => \"file.csv\");\ncsv (in => $aoa, out => $fh);\ncsv (in => $aoa, out =>   STDOUT);\ncsv (in => $aoa, out =>  *STDOUT);\ncsv (in => $aoa, out => \\*STDOUT);\ncsv (in => $aoa, out => \\my $data);\ncsv (in => $aoa, out =>  undef);\ncsv (in => $aoa, out => \\\"skip\");\n\ncsv (in => $fh,  out => \\@aoa);\ncsv (in => $fh,  out => \\@aoh, bom => 1);\ncsv (in => $fh,  out => \\%hsh, key => \"key\");\n\nIn output mode, the default CSV options when producing CSV are\n\neol       => \"\\r\\n\"\n\nThe \"fragment\" attribute is ignored in output mode.\n\n\"out\" can be a file name (e.g. \"file.csv\"), which will be opened for writing and closed when\nfinished, a file handle (e.g. $fh or \"FH\"), a reference to a glob (e.g. \"\\*STDOUT\"), the glob\nitself (e.g. *STDOUT), or a reference to a scalar (e.g. \"\\my $data\").\n\ncsv (in => sub { $sth->fetch },            out => \"dump.csv\");\ncsv (in => sub { $sth->fetchrowhashref }, out => \"dump.csv\",\nheaders => $sth->{NAMElc});\n\nWhen a code-ref is used for \"in\", the output is generated per invocation, so no buffering is\ninvolved. This implies that there is no size restriction on the number of records. The \"csv\"\nfunction ends when the coderef returns a false value.\n\nIf \"out\" is set to a reference of the literal string \"skip\", the output will be suppressed\ncompletely, which might be useful in combination with a filter for side effects only.\n\nmy %cache;\ncsv (in    => \"dump.csv\",\nout   => \\\"skip\",\nonin => sub { $cache{$[1][1]}++ });\n\nCurrently, setting \"out\" to any false value (\"undef\", \"\", 0) will be equivalent to \"\\\"skip\"\".\n\nIf the \"in\" argument point to something to parse, and the \"out\" is set to a reference to an\n\"ARRAY\" or a \"HASH\", the output is appended to the data in the existing reference. The result of\nthe parse should match what exists in the reference passed. This might come handy when you have\nto parse a set of files with similar content (like data stored per period) and you want to\ncollect that into a single data structure:\n\nmy %hash;\ncsv (in => $, out => \\%hash, key => \"id\") for sort glob \"foo-[0-9]*.csv\";\n\nmy @list; # List of arrays\ncsv (in => $, out => \\@list)              for sort glob \"foo-[0-9]*.csv\";\n\nmy @list; # List of hashes\ncsv (in => $, out => \\@list, bom => 1)    for sort glob \"foo-[0-9]*.csv\";\n\nencoding\nIf passed, it should be an encoding accepted by the \":encoding()\" option to \"open\". There is no\ndefault value. This attribute does not work in perl 5.6.x. \"encoding\" can be abbreviated to\n\"enc\" for ease of use in command line invocations.\n\nIf \"encoding\" is set to the literal value \"auto\", the method \"header\" will be invoked on the\nopened stream to check if there is a BOM and set the encoding accordingly. This is equal to\npassing a true value in the option \"detectbom\".\n\nEncodings can be stacked, as supported by \"binmode\":\n\n# Using PerlIO::via::gzip\ncsv (in       => \\@csv,\nout      => \"test.csv:via.gz\",\nencoding => \":via(gzip):encoding(utf-8)\",\n);\n$aoa = csv (in => \"test.csv:via.gz\",  encoding => \":via(gzip)\");\n\n# Using PerlIO::gzip\ncsv (in       => \\@csv,\nout      => \"test.csv:via.gz\",\nencoding => \":gzip:encoding(utf-8)\",\n);\n$aoa = csv (in => \"test.csv:gzip.gz\", encoding => \":gzip\");\n\ndetectbom\nIf \"detectbom\" is given, the method \"header\" will be invoked on the opened stream to check if\nthere is a BOM and set the encoding accordingly.\n\n\"detectbom\" can be abbreviated to \"bom\".\n\nThis is the same as setting \"encoding\" to \"auto\".\n\nNote that as the method \"header\" is invoked, its default is to also set the headers.\n\nheaders\nIf this attribute is not given, the default behavior is to produce an array of arrays.\n\nIf \"headers\" is supplied, it should be an anonymous list of column names, an anonymous hashref,\na coderef, or a literal flag: \"auto\", \"lc\", \"uc\", or \"skip\".\n\nskip\nWhen \"skip\" is used, the header will not be included in the output.\n\nmy $aoa = csv (in => $fh, headers => \"skip\");\n\nauto\nIf \"auto\" is used, the first line of the \"CSV\" source will be read as the list of field\nheaders and used to produce an array of hashes.\n\nmy $aoh = csv (in => $fh, headers => \"auto\");\n\nlc\nIf \"lc\" is used, the first line of the \"CSV\" source will be read as the list of field headers\nmapped to lower case and used to produce an array of hashes. This is a variation of \"auto\".\n\nmy $aoh = csv (in => $fh, headers => \"lc\");\n\nuc\nIf \"uc\" is used, the first line of the \"CSV\" source will be read as the list of field headers\nmapped to upper case and used to produce an array of hashes. This is a variation of \"auto\".\n\nmy $aoh = csv (in => $fh, headers => \"uc\");\n\nCODE\nIf a coderef is used, the first line of the \"CSV\" source will be read as the list of mangled\nfield headers in which each field is passed as the only argument to the coderef. This list is\nused to produce an array of hashes.\n\nmy $aoh = csv (in      => $fh,\nheaders => sub { lc ($[0]) =~ s/kode/code/gr });\n\nthis example is a variation of using \"lc\" where all occurrences of \"kode\" are replaced with\n\"code\".\n\nARRAY\nIf \"headers\" is an anonymous list, the entries in the list will be used as field names. The\nfirst line is considered data instead of headers.\n\nmy $aoh = csv (in => $fh, headers => [qw( Foo Bar )]);\ncsv (in => $aoa, out => $fh, headers => [qw( code description price )]);\n\nHASH\nIf \"headers\" is a hash reference, this implies \"auto\", but header fields that exist as key in\nthe hashref will be replaced by the value for that key. Given a CSV file like\n\npost-kode,city,name,id number,fubble\n1234AA,Duckstad,Donald,13,\"X313DF\"\n\nusing\n\ncsv (headers => { \"post-kode\" => \"pc\", \"id number\" => \"ID\" }, ...\n\nwill return an entry like\n\n{ pc     => \"1234AA\",\ncity   => \"Duckstad\",\nname   => \"Donald\",\nID     => \"13\",\nfubble => \"X313DF\",\n}\n\nSee also \"mungecolumnnames\" and \"setcolumnnames\".\n\nmungecolumnnames\nIf \"mungecolumnnames\" is set, the method \"header\" is invoked on the opened stream with all\nmatching arguments to detect and set the headers.\n\n\"mungecolumnnames\" can be abbreviated to \"munge\".\n\nkey\nIf passed, will default \"headers\" to \"auto\" and return a hashref instead of an array of hashes.\nAllowed values are simple scalars or array-references where the first element is the joiner and\nthe rest are the fields to join to combine the key.\n\nmy $ref = csv (in => \"test.csv\", key => \"code\");\nmy $ref = csv (in => \"test.csv\", key => [ \":\" => \"code\", \"color\" ]);\n\nwith test.csv like\n\ncode,product,price,color\n1,pc,850,gray\n2,keyboard,12,white\n3,mouse,5,black\n\nthe first example will return\n\n{ 1   => {\ncode    => 1,\ncolor   => 'gray',\nprice   => 850,\nproduct => 'pc'\n},\n2   => {\ncode    => 2,\ncolor   => 'white',\nprice   => 12,\nproduct => 'keyboard'\n},\n3   => {\ncode    => 3,\ncolor   => 'black',\nprice   => 5,\nproduct => 'mouse'\n}\n}\n\nthe second example will return\n\n{ \"1:gray\"    => {\ncode    => 1,\ncolor   => 'gray',\nprice   => 850,\nproduct => 'pc'\n},\n\"2:white\"   => {\ncode    => 2,\ncolor   => 'white',\nprice   => 12,\nproduct => 'keyboard'\n},\n\"3:black\"   => {\ncode    => 3,\ncolor   => 'black',\nprice   => 5,\nproduct => 'mouse'\n}\n}\n\nThe \"key\" attribute can be combined with \"headers\" for \"CSV\" date that has no header line, like\n\nmy $ref = csv (\nin      => \"foo.csv\",\nheaders => [qw( cfoo foo bar description stock )],\nkey     =>     \"cfoo\",\n);\n\nvalue\nUsed to create key-value hashes.\n\nOnly allowed when \"key\" is valid. A \"value\" can be either a single column label or an anonymous\nlist of column labels. In the first case, the value will be a simple scalar value, in the latter\ncase, it will be a hashref.\n\nmy $ref = csv (in => \"test.csv\", key   => \"code\",\nvalue => \"price\");\nmy $ref = csv (in => \"test.csv\", key   => \"code\",\nvalue => [ \"product\", \"price\" ]);\nmy $ref = csv (in => \"test.csv\", key   => [ \":\" => \"code\", \"color\" ],\nvalue => \"price\");\nmy $ref = csv (in => \"test.csv\", key   => [ \":\" => \"code\", \"color\" ],\nvalue => [ \"product\", \"price\" ]);\n\nwith test.csv like\n\ncode,product,price,color\n1,pc,850,gray\n2,keyboard,12,white\n3,mouse,5,black\n\nthe first example will return\n\n{ 1 => 850,\n2 =>  12,\n3 =>   5,\n}\n\nthe second example will return\n\n{ 1   => {\nprice   => 850,\nproduct => 'pc'\n},\n2   => {\nprice   => 12,\nproduct => 'keyboard'\n},\n3   => {\nprice   => 5,\nproduct => 'mouse'\n}\n}\n\nthe third example will return\n\n{ \"1:gray\"    => 850,\n\"2:white\"   =>  12,\n\"3:black\"   =>   5,\n}\n\nthe fourth example will return\n\n{ \"1:gray\"    => {\nprice   => 850,\nproduct => 'pc'\n},\n\"2:white\"   => {\nprice   => 12,\nproduct => 'keyboard'\n},\n\"3:black\"   => {\nprice   => 5,\nproduct => 'mouse'\n}\n}\n\nkeepheaders\nWhen using hashes, keep the column names into the arrayref passed, so all headers are available\nafter the call in the original order.\n\nmy $aoh = csv (in => \"file.csv\", keepheaders => \\my @hdr);\n\nThis attribute can be abbreviated to \"kh\" or passed as \"keepcolumnnames\".\n\nThis attribute implies a default of \"auto\" for the \"headers\" attribute.\n\nfragment\nOnly output the fragment as defined in the \"fragment\" method. This option is ignored when\n*generating* \"CSV\". See \"out\".\n\nCombining all of them could give something like\n\nuse Text::CSVXS qw( csv );\nmy $aoh = csv (\nin       => \"test.txt\",\nencoding => \"utf-8\",\nheaders  => \"auto\",\nsepchar => \"|\",\nfragment => \"row=3;6-9;15-*\",\n);\nsay $aoh->[15]{Foo};\n\nsepset\nIf \"sepset\" is set, the method \"header\" is invoked on the opened stream to detect and set\n\"sepchar\" with the given set.\n\n\"sepset\" can be abbreviated to \"seps\".\n\nNote that as the \"header\" method is invoked, its default is to also set the headers.\n\nsetcolumnnames\nIf \"setcolumnnames\" is passed, the method \"header\" is invoked on the opened stream with all\narguments meant for \"header\".\n\nIf \"setcolumnnames\" is passed as a false value, the content of the first row is only preserved\nif the output is AoA:\n\nWith an input-file like\n\nbAr,foo\n1,2\n3,4,5\n\nThis call\n\nmy $aoa = csv (in => $file, setcolumnnames => 0);\n\nwill result in\n\n[[ \"bar\", \"foo\"     ],\n[ \"1\",   \"2\"       ],\n[ \"3\",   \"4\",  \"5\" ]]\n\nand\n\nmy $aoa = csv (in => $file, setcolumnnames => 0, munge => \"none\");\n\nwill result in\n\n[[ \"bAr\", \"foo\"     ],\n[ \"1\",   \"2\"       ],\n[ \"3\",   \"4\",  \"5\" ]]\n",
            "subsections": [
                {
                    "name": "Callbacks",
                    "content": "Callbacks enable actions triggered from the *inside* of Text::CSVXS.\n\nWhile most of what this enables can easily be done in an unrolled loop as described in the\n\"SYNOPSIS\" callbacks can be used to meet special demands or enhance the \"csv\" function.\n\nerror\n$csv->callbacks (error => sub { $csv->SetDiag (0) });\n\nthe \"error\" callback is invoked when an error occurs, but *only* when \"autodiag\" is set to a\ntrue value. A callback is invoked with the values returned by \"errordiag\":\n\nmy ($c, $s);\n\nsub ignore3006 {\nmy ($err, $msg, $pos, $recno, $fldno) = @;\nif ($err == 3006) {\n# ignore this error\n($c, $s) = (undef, undef);\nText::CSVXS->SetDiag (0);\n}\n# Any other error\nreturn;\n} # ignore3006\n\n$csv->callbacks (error => \\&ignore3006);\n$csv->bindcolumns (\\$c, \\$s);\nwhile ($csv->getline ($fh)) {\n# Error 3006 will not stop the loop\n}\n\nafterparse\n$csv->callbacks (afterparse => sub { push @{$[1]}, \"NEW\" });\nwhile (my $row = $csv->getline ($fh)) {\n$row->[-1] eq \"NEW\";\n}\n\nThis callback is invoked after parsing with \"getline\" only if no error occurred. The callback\nis invoked with two arguments: the current \"CSV\" parser object and an array reference to the\nfields parsed.\n\nThe return code of the callback is ignored unless it is a reference to the string \"skip\", in\nwhich case the record will be skipped in \"getlineall\".\n\nsub addfromdb {\nmy ($csv, $row) = @;\n$sth->execute ($row->[4]);\npush @$row, $sth->fetchrowarray;\n} # addfromdb\n\nmy $aoa = csv (in => \"file.csv\", callbacks => {\nafterparse => \\&addfromdb });\n\nThis hook can be used for validation:\n\nFAIL\nDie if any of the records does not validate a rule:\n\nafterparse => sub {\n$[1][4] =~ m/^[0-9]{4}\\s?[A-Z]{2}$/ or\ndie \"5th field does not have a valid Dutch zipcode\";\n}\n\nDEFAULT\nReplace invalid fields with a default value:\n\nafterparse => sub { $[1][2] =~ m/^\\d+$/ or $[1][2] = 0 }\n\nSKIP\nSkip records that have invalid fields (only applies to \"getlineall\"):\n\nafterparse => sub { $[1][0] =~ m/^\\d+$/ or return \\\"skip\"; }\n\nbeforeprint\nmy $idx = 1;\n$csv->callbacks (beforeprint => sub { $[1][0] = $idx++ });\n$csv->print (*STDOUT, [ 0, $ ]) for @members;\n\nThis callback is invoked before printing with \"print\" only if no error occurred. The callback\nis invoked with two arguments: the current \"CSV\" parser object and an array reference to the\nfields passed.\n\nThe return code of the callback is ignored.\n\nsub max4fields {\nmy ($csv, $row) = @;\n@$row > 4 and splice @$row, 4;\n} # max4fields\n\ncsv (in => csv (in => \"file.csv\"), out => *STDOUT,\ncallbacks => { beforeprint => \\&max4fields });\n\nThis callback is not active for \"combine\".\n\nCallbacks for csv ()\nThe \"csv\" allows for some callbacks that do not integrate in XS internals but only feature the\n\"csv\" function.\n\ncsv (in        => \"file.csv\",\ncallbacks => {\nfilter       => { 6 => sub { $ > 15 } },    # first\nafterparse  => sub { say \"AFTER PARSE\";  }, # first\nafterin     => sub { say \"AFTER IN\";     }, # second\nonin        => sub { say \"ON IN\";        }, # third\n},\n);\n\ncsv (in        => $aoh,\nout       => \"file.csv\",\ncallbacks => {\nonin        => sub { say \"ON IN\";        }, # first\nbeforeout   => sub { say \"BEFORE OUT\";   }, # second\nbeforeprint => sub { say \"BEFORE PRINT\"; }, # third\n},\n);\n\nfilter\nThis callback can be used to filter records. It is called just after a new record has been\nscanned. The callback accepts a:\n\nhashref\nThe keys are the index to the row (the field name or field number, 1-based) and the values\nare subs to return a true or false value.\n\ncsv (in => \"file.csv\", filter => {\n3 => sub { m/a/ },       # third field should contain an \"a\"\n5 => sub { length > 4 }, # length of the 5th field minimal 5\n});\n\ncsv (in => \"file.csv\", filter => { foo => sub { $ > 4 }});\n\nIf the keys to the filter hash contain any character that is not a digit it will also\nimplicitly set \"headers\" to \"auto\" unless \"headers\" was already passed as argument. When\nheaders are active, returning an array of hashes, the filter is not applicable to the header\nitself.\n\nAll sub results should match, as in AND.\n\nThe context of the callback sets $ localized to the field indicated by the filter. The two\narguments are as with all other callbacks, so the other fields in the current row can be\nseen:\n\nfilter => { 3 => sub { $ > 100 ? $[1][1] =~ m/A/ : $[1][6] =~ m/B/ }}\n\nIf the context is set to return a list of hashes (\"headers\" is defined), the current record\nwill also be available in the localized %:\n\nfilter => { 3 => sub { $ > 100 && ${foo} =~ m/A/ && ${bar} < 1000  }}\n\nIf the filter is used to *alter* the content by changing $, make sure that the sub returns\ntrue in order not to have that record skipped:\n\nfilter => { 2 => sub { $ = uc }}\n\nwill upper-case the second field, and then skip it if the resulting content evaluates to\nfalse. To always accept, end with truth:\n\nfilter => { 2 => sub { $ = uc; 1 }}\n\ncoderef\ncsv (in => \"file.csv\", filter => sub { $n++; 0; });\n\nIf the argument to \"filter\" is a coderef, it is an alias or shortcut to a filter on column\n0:\n\ncsv (filter => sub { $n++; 0 });\n\nis equal to\n\ncsv (filter => { 0 => sub { $n++; 0 });\n\nfilter-name\ncsv (in => \"file.csv\", filter => \"notblank\");\ncsv (in => \"file.csv\", filter => \"notempty\");\ncsv (in => \"file.csv\", filter => \"filled\");\n\nThese are predefined filters\n\nGiven a file like (line numbers prefixed for doc purpose only):\n\n1:1,2,3\n2:\n3:,\n4:\"\"\n5:,,\n6:, ,\n7:\"\",\n8:\" \"\n9:4,5,6\n\nnotblank\nFilter out the blank lines\n\nThis filter is a shortcut for\n\nfilter => { 0 => sub { @{$[1]} > 1 or\ndefined $[1][0] && $[1][0] ne \"\" } }\n\nDue to the implementation, it is currently impossible to also filter lines that consists\nonly of a quoted empty field. These lines are also considered blank lines.\n\nWith the given example, lines 2 and 4 will be skipped.\n\nnotempty\nFilter out lines where all the fields are empty.\n\nThis filter is a shortcut for\n\nfilter => { 0 => sub { grep { defined && $ ne \"\" } @{$[1]} } }\n\nA space is not regarded being empty, so given the example data, lines 2, 3, 4, 5, and 7\nare skipped.\n\nfilled\nFilter out lines that have no visible data\n\nThis filter is a shortcut for\n\nfilter => { 0 => sub { grep { defined && m/\\S/ } @{$[1]} } }\n\nThis filter rejects all lines that *not* have at least one field that does not evaluate to\nthe empty string.\n\nWith the given example data, this filter would skip lines 2 through 8.\n\nOne could also use modules like Types::Standard:\n\nuse Types::Standard -types;\n\nmy $type   = Tuple[Str, Str, Int, Bool, Optional[Num]];\nmy $check  = $type->compiledcheck;\n\n# filter with compiled check and warnings\nmy $aoa = csv (\nin     => \\$data,\nfilter => {\n0 => sub {\nmy $ok = $check->($[1]) or\nwarn $type->getmessage ($[1]), \"\\n\";\nreturn $ok;\n},\n},\n);\n\nafterin\nThis callback is invoked for each record after all records have been parsed but before\nreturning the reference to the caller. The hook is invoked with two arguments: the current\n\"CSV\" parser object and a reference to the record. The reference can be a reference to a HASH\nor a reference to an ARRAY as determined by the arguments.\n\nThis callback can also be passed as an attribute without the \"callbacks\" wrapper.\n\nbeforeout\nThis callback is invoked for each record before the record is printed. The hook is invoked\nwith two arguments: the current \"CSV\" parser object and a reference to the record. The\nreference can be a reference to a HASH or a reference to an ARRAY as determined by the\narguments.\n\nThis callback can also be passed as an attribute without the \"callbacks\" wrapper.\n\nThis callback makes the row available in % if the row is a hashref. In this case % is\nwritable and will change the original row.\n\nonin\nThis callback acts exactly as the \"afterin\" or the \"beforeout\" hooks.\n\nThis callback can also be passed as an attribute without the \"callbacks\" wrapper.\n\nThis callback makes the row available in % if the row is a hashref. In this case % is\nwritable and will change the original row. So e.g. with\n\nmy $aoh = csv (\nin      => \\\"foo\\n1\\n2\\n\",\nheaders => \"auto\",\nonin   => sub { ${bar} = 2; },\n);\n\n$aoh will be:\n\n[ { foo => 1,\nbar => 2,\n}\n{ foo => 2,\nbar => 2,\n}\n]\n\ncsv\nThe *function* \"csv\" can also be called as a method or with an existing Text::CSVXS object.\nThis could help if the function is to be invoked a lot of times and the overhead of creating\nthe object internally over and over again would be prevented by passing an existing instance.\n\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\n\nmy $aoa = $csv->csv (in => $fh);\nmy $aoa = csv (in => $fh, csv => $csv);\n\nboth act the same. Running this 20000 times on a 20 lines CSV file, showed a 53% speedup.\n"
                }
            ]
        },
        "INTERNALS": {
            "content": "Combine (...)\nParse (...)\n\nThe arguments to these internal functions are deliberately not described or documented in order\nto enable the module authors make changes it when they feel the need for it. Using them is\nhighly discouraged as the API may change in future releases.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "",
            "subsections": [
                {
                    "name": "Reading a CSV file line by line:",
                    "content": "my $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<\", \"file.csv\" or die \"file.csv: $!\";\nwhile (my $row = $csv->getline ($fh)) {\n# do something with @$row\n}\nclose $fh or die \"file.csv: $!\";\n\nor\n\nmy $aoa = csv (in => \"file.csv\", onin => sub {\n# do something with %\n});\n\nReading only a single column\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<\", \"file.csv\" or die \"file.csv: $!\";\n# get only the 4th column\nmy @column = map { $->[3] } @{$csv->getlineall ($fh)};\nclose $fh or die \"file.csv: $!\";\n\nwith \"csv\", you could do\n\nmy @column = map { $->[0] }\n@{csv (in => \"file.csv\", fragment => \"col=4\")};\n"
                },
                {
                    "name": "Parsing CSV strings:",
                    "content": "my $csv = Text::CSVXS->new ({ keepmetainfo => 1, binary => 1 });\n\nmy $sampleinputstring =\nqq{\"I said, \"\"Hi!\"\"\",Yes,\"\",2.34,,\"1.09\",\"\\x{20ac}\",};\nif ($csv->parse ($sampleinputstring)) {\nmy @field = $csv->fields;\nforeach my $col (0 .. $#field) {\nmy $quo = $csv->isquoted ($col) ? $csv->{quotechar} : \"\";\nprintf \"%2d: %s%s%s\\n\", $col, $quo, $field[$col], $quo;\n}\n}\nelse {\nprint STDERR \"parse () failed on argument: \",\n$csv->errorinput, \"\\n\";\n$csv->errordiag ();\n}\n\nParsing CSV from memory\nGiven a complete CSV data-set in scalar $data, generate a list of lists to represent the rows\nand fields\n\n# The data\nmy $data = join \"\\r\\n\" => map { join \",\" => 0 .. 5 } 0 .. 5;\n\n# in a loop\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });\nopen my $fh, \"<\", \\$data;\nmy @foo;\nwhile (my $row = $csv->getline ($fh)) {\npush @foo, $row;\n}\nclose $fh;\n\n# a single call\nmy $foo = csv (in => \\$data);\n"
                },
                {
                    "name": "Printing CSV data",
                    "content": "The fast way: using \"print\"\nAn example for creating \"CSV\" files using the \"print\" method:\n\nmy $csv = Text::CSVXS->new ({ binary => 1, eol => $/ });\nopen my $fh, \">\", \"foo.csv\" or die \"foo.csv: $!\";\nfor (1 .. 10) {\n$csv->print ($fh, [ $, \"$\" ]) or $csv->errordiag;\n}\nclose $fh or die \"$tbl.csv: $!\";\n\nThe slow way: using \"combine\" and \"string\"\nor using the slower \"combine\" and \"string\" methods:\n\nmy $csv = Text::CSVXS->new;\n\nopen my $csvfh, \">\", \"hello.csv\" or die \"hello.csv: $!\";\n\nmy @sampleinputfields = (\n'You said, \"Hello!\"',   5.67,\n'\"Surely\"',   '',   '3.14159');\nif ($csv->combine (@sampleinputfields)) {\nprint $csvfh $csv->string, \"\\n\";\n}\nelse {\nprint \"combine () failed on argument: \",\n$csv->errorinput, \"\\n\";\n}\nclose $csvfh or die \"hello.csv: $!\";\n\nGenerating CSV into memory\nFormat a data-set (@foo) into a scalar value in memory ($data):\n\n# The data\nmy @foo = map { [ 0 .. 5 ] } 0 .. 3;\n\n# in a loop\nmy $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1, eol => \"\\r\\n\" });\nopen my $fh, \">\", \\my $data;\n$csv->print ($fh, $) for @foo;\nclose $fh;\n\n# a single call\ncsv (in => \\@foo, out => \\my $data);\n"
                },
                {
                    "name": "Rewriting CSV",
                    "content": "Rewrite \"CSV\" files with \";\" as separator character to well-formed \"CSV\":\n\nuse Text::CSVXS qw( csv );\ncsv (in => csv (in => \"bad.csv\", sepchar => \";\"), out => *STDOUT);\n\nAs \"STDOUT\" is now default in \"csv\", a one-liner converting a UTF-16 CSV file with BOM and\nTAB-separation to valid UTF-8 CSV could be:\n\n$ perl -C3 -MText::CSVXS=csv -we\\\n'csv(in=>\"utf16tab.csv\",encoding=>\"utf16\",sep=>\"\\t\")' >utf8.csv\n"
                },
                {
                    "name": "Dumping database tables to CSV",
                    "content": "Dumping a database table can be simple as this (TIMTOWTDI):\n\nmy $dbh = DBI->connect (...);\nmy $sql = \"select * from foo\";\n\n# using your own loop\nopen my $fh, \">\", \"foo.csv\" or die \"foo.csv: $!\\n\";\nmy $csv = Text::CSVXS->new ({ binary => 1, eol => \"\\r\\n\" });\nmy $sth = $dbh->prepare ($sql); $sth->execute;\n$csv->print ($fh, $sth->{NAMElc});\nwhile (my $row = $sth->fetch) {\n$csv->print ($fh, $row);\n}\n\n# using the csv function, all in memory\ncsv (out => \"foo.csv\", in => $dbh->selectallarrayref ($sql));\n\n# using the csv function, streaming with callbacks\nmy $sth = $dbh->prepare ($sql); $sth->execute;\ncsv (out => \"foo.csv\", in => sub { $sth->fetch            });\ncsv (out => \"foo.csv\", in => sub { $sth->fetchrowhashref });\n\nNote that this does not discriminate between \"empty\" values and NULL-values from the database,\nas both will be the same empty field in CSV. To enable distinction between the two, use\n\"quoteempty\".\n\ncsv (out => \"foo.csv\", in => sub { $sth->fetch }, quoteempty => 1);\n\nIf the database import utility supports special sequences to insert \"NULL\" values into the\ndatabase, like MySQL/MariaDB supports \"\\N\", use a filter or a map\n\ncsv (out => \"foo.csv\", in => sub { $sth->fetch },\nonin => sub { $ //= \"\\\\N\" for @{$[1]} });\n\nwhile (my $row = $sth->fetch) {\n$csv->print ($fh, [ map { $ // \"\\\\N\" } @$row ]);\n}\n\nNote that this will not work as expected when choosing the backslash (\"\\\") as \"escapechar\", as\nthat will cause the \"\\\" to need to be escaped by yet another \"\\\", which will cause the field to\nneed quotation and thus ending up as \"\\\\N\" instead of \"\\N\". See also \"undefstr\".\n\ncsv (out => \"foo.csv\", in => sub { $sth->fetch }, undefstr => \"\\\\N\");\n\nThese special sequences are not recognized by Text::CSVXS on parsing the CSV generated like\nthis, but map and filter are your friends again\n\nwhile (my $row = $csv->getline ($fh)) {\n$sth->execute (map { $ eq \"\\\\N\" ? undef : $ } @$row);\n}\n\ncsv (in => \"foo.csv\", filter => { 1 => sub {\n$sth->execute (map { $ eq \"\\\\N\" ? undef : $ } @{$[1]}); 0; }});\n"
                },
                {
                    "name": "Converting CSV to JSON",
                    "content": "use Text::CSVXS qw( csv );\nuse JSON; # or Cpanel::JSON::XS for better performance\n\n# AoA (no header interpretation)\nsay encodejson (csv (in => \"file.csv\"));\n\n# AoH (convert to structures)\nsay encodejson (csv (in => \"file.csv\", bom => 1));\n\nYes, it is that simple.\n"
                },
                {
                    "name": "The examples folder",
                    "content": "For more extended examples, see the examples/ 1. sub-directory in the original distribution or\nthe git repository 2.\n\n1. https://github.com/Tux/Text-CSVXS/tree/master/examples\n2. https://github.com/Tux/Text-CSVXS\n\nThe following files can be found there:\n\nparser-xs.pl\nThis can be used as a boilerplate to parse invalid \"CSV\" and parse beyond (expected) errors\nalternative to using the \"error\" callback.\n\n$ perl examples/parser-xs.pl bad.csv >good.csv\n\ncsv-check\nThis is a command-line tool that uses parser-xs.pl techniques to check the \"CSV\" file and\nreport on its content.\n\n$ csv-check files/utf8.csv\nChecked files/utf8.csv  with csv-check 1.9\nusing Text::CSVXS 1.32 with perl 5.26.0 and Unicode 9.0.0\nOK: rows: 1, columns: 2\nsep = <,>, quo = <\">, bin = <1>, eol = <\"\\n\">\n\ncsv-split\nThis command splits \"CSV\" files into smaller files, keeping (part of) the header. Options\ninclude maximum number of (data) rows per file and maximum number of columns per file or a\ncombination of the two.\n\ncsv2xls\nA script to convert \"CSV\" to Microsoft Excel (\"XLS\"). This requires extra modules Date::Calc\nand Spreadsheet::WriteExcel. The converter accepts various options and can produce UTF-8\ncompliant Excel files.\n\ncsv2xlsx\nA script to convert \"CSV\" to Microsoft Excel (\"XLSX\"). This requires the modules Date::Calc\nand Spreadsheet::Writer::XLSX. The converter does accept various options including merging\nseveral \"CSV\" files into a single Excel file.\n\ncsvdiff\nA script that provides colorized diff on sorted CSV files, assuming first line is header and\nfirst field is the key. Output options include colorized ANSI escape codes or HTML.\n\n$ csvdiff --html --output=diff.html file1.csv file2.csv\n\nrewrite.pl\nA script to rewrite (in)valid CSV into valid CSV files. Script has options to generate\nconfusing CSV files or CSV files that conform to Dutch MS-Excel exports (using \";\" as\nseparation).\n\nScript - by default - honors BOM and auto-detects separation converting it to default standard\nCSV with \",\" as separator.\n"
                }
            ]
        },
        "CAVEATS": {
            "content": "Text::CSVXS is *not* designed to detect the characters used to quote and separate fields. The\nparsing is done using predefined (default) settings. In the examples sub-directory, you can find\nscripts that demonstrate how you could try to detect these characters yourself.\n",
            "subsections": [
                {
                    "name": "Microsoft Excel",
                    "content": "The import/export from Microsoft Excel is a *risky task*, according to the documentation in\n\"Text::CSV::Separator\". Microsoft uses the system's list separator defined in the regional\nsettings, which happens to be a semicolon for Dutch, German and Spanish (and probably some\nothers as well). For the English locale, the default is a comma. In Windows however, the user is\nfree to choose a predefined locale, and then change *every* individual setting in it, so\nchecking the locale is no solution.\n\nAs of version 1.17, a lone first line with just\n\nsep=;\n\nwill be recognized and honored when parsing with \"getline\".\n"
                }
            ]
        },
        "TODO": {
            "content": "More Errors & Warnings\nNew extensions ought to be clear and concise in reporting what error has occurred where and\nwhy, and maybe also offer a remedy to the problem.\n\n\"errordiag\" is a (very) good start, but there is more work to be done in this area.\n\nBasic calls should croak or warn on illegal parameters. Errors should be documented.\n\nsetting meta info\nFuture extensions might include extending the \"metainfo\", \"isquoted\", and \"isbinary\" to\naccept setting these flags for fields, so you can specify which fields are quoted in the\n\"combine\"/\"string\" combination.\n\n$csv->metainfo (0, 1, 1, 3, 0, 0);\n$csv->isquoted (3, 1);\n\nMetadata Vocabulary for Tabular Data <http://w3c.github.io/csvw/metadata/> (a W3C editor's\ndraft) could be an example for supporting more metadata.\n\nParse the whole file at once\nImplement new methods or functions that enable parsing of a complete file at once, returning a\nlist of hashes. Possible extension to this could be to enable a column selection on the call:\n\nmy @AoH = $csv->parsefile ($filename, { cols => [ 1, 4..8, 12 ]});\n\nreturning something like\n\n[ { fields => [ 1, 2, \"foo\", 4.5, undef, \"\", 8 ],\nflags  => [ ... ],\n},\n{ fields => [ ... ],\n.\n},\n]\n\nNote that the \"csv\" function already supports most of this, but does not return flags.\n\"getlineall\" returns all rows for an open stream, but this will not return flags either.\n\"fragment\" can reduce the required rows *or* columns, but cannot combine them.\n\nCookbook\nWrite a document that has recipes for most known non-standard (and maybe some standard) \"CSV\"\nformats, including formats that use \"TAB\", \";\", \"|\", or other non-comma separators.\n\nExamples could be taken from W3C's CSV on the Web: Use Cases and Requirements\n<http://w3c.github.io/csvw/use-cases-and-requirements/index.html>\n\nSteal\nSteal good new ideas and features from PapaParse <http://papaparse.com> or csvkit\n<http://csvkit.readthedocs.org>.\n\nRaku support\nRaku support can be found here <https://github.com/Tux/CSV>. The interface is richer in\nsupport than the Perl5 API, as Raku supports more types.\n\nThe Raku version does not (yet) support pure binary CSV datasets.\n\nNOT TODO\ncombined methods\nRequests for adding means (methods) that combine \"combine\" and \"string\" in a single call will\nnot be honored (use \"print\" instead). Likewise for \"parse\" and \"fields\" (use \"getline\"\ninstead), given the problems with embedded newlines.\n",
            "subsections": [
                {
                    "name": "Release plan",
                    "content": "No guarantees, but this is what I had in mind some time ago:\n\n* DIAGNOSTICS section in pod to *describe* the errors (see below)\n"
                }
            ]
        },
        "EBCDIC": {
            "content": "Everything should now work on native EBCDIC systems. As the test does not cover all possible\ncodepoints and Encode does not support \"utf-ebcdic\", there is no guarantee that all handling of\nUnicode is done correct.\n\nOpening \"EBCDIC\" encoded files on \"ASCII\"+ systems is likely to succeed using Encode's \"cp37\",\n\"cp1047\", or \"posix-bc\":\n\nopen my $fh, \"<:encoding(cp1047)\", \"ebcdicfile.csv\" or die \"...\";\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "Still under construction ...\n\nIf an error occurs, \"$csv->errordiag\" can be used to get information on the cause of the\nfailure. Note that for speed reasons the internal value is never cleared on success, so using\nthe value returned by \"errordiag\" in normal cases - when no error occurred - may cause\nunexpected results.\n\nIf the constructor failed, the cause can be found using \"errordiag\" as a class method, like\n\"Text::CSVXS->errordiag\".\n\nThe \"$csv->errordiag\" method is automatically invoked upon error when the contractor was called\nwith \"autodiag\" set to 1 or 2, or when autodie is in effect. When set to 1, this will cause a\n\"warn\" with the error message, when set to 2, it will \"die\". \"2012 - EOF\" is excluded from\n\"autodiag\" reports.\n\nErrors can be (individually) caught using the \"error\" callback.\n\nThe errors as described below are available. I have tried to make the error itself explanatory\nenough, but more descriptions will be added. For most of these errors, the first three capitals\ndescribe the error category:\n\n* INI\n\nInitialization error or option conflict.\n\n* ECR\n\nCarriage-Return related parse error.\n\n* EOF\n\nEnd-Of-File related parse error.\n\n* EIQ\n\nParse error inside quotation.\n\n* EIF\n\nParse error inside field.\n\n* ECB\n\nCombine error.\n\n* EHR\n\nHashRef parse related error.\n\nAnd below should be the complete list of error codes that can be returned:\n\n* 1001 \"INI - sepchar is equal to quotechar or escapechar\"\n\nThe separation character cannot be equal to the quotation character or to the escape\ncharacter, as this would invalidate all parsing rules.\n\n* 1002 \"INI - allowwhitespace with escapechar or quotechar SP or TAB\"\n\nUsing the \"allowwhitespace\" attribute when either \"quotechar\" or \"escapechar\" is equal to\n\"SPACE\" or \"TAB\" is too ambiguous to allow.\n\n* 1003 \"INI - \\r or \\n in main attr not allowed\"\n\nUsing default \"eol\" characters in either \"sepchar\", \"quotechar\", or \"escapechar\" is not\nallowed.\n\n* 1004 \"INI - callbacks should be undef or a hashref\"\n\nThe \"callbacks\" attribute only allows one to be \"undef\" or a hash reference.\n\n* 1005 \"INI - EOL too long\"\n\nThe value passed for EOL is exceeding its maximum length (16).\n\n* 1006 \"INI - SEP too long\"\n\nThe value passed for SEP is exceeding its maximum length (16).\n\n* 1007 \"INI - QUOTE too long\"\n\nThe value passed for QUOTE is exceeding its maximum length (16).\n\n* 1008 \"INI - SEP undefined\"\n\nThe value passed for SEP should be defined and not empty.\n\n* 1010 \"INI - the header is empty\"\n\nThe header line parsed in the \"header\" is empty.\n\n* 1011 \"INI - the header contains more than one valid separator\"\n\nThe header line parsed in the \"header\" contains more than one (unique) separator character out\nof the allowed set of separators.\n\n* 1012 \"INI - the header contains an empty field\"\n\nThe header line parsed in the \"header\" contains an empty field.\n\n* 1013 \"INI - the header contains nun-unique fields\"\n\nThe header line parsed in the \"header\" contains at least two identical fields.\n\n* 1014 \"INI - header called on undefined stream\"\n\nThe header line cannot be parsed from an undefined source.\n\n* 1500 \"PRM - Invalid/unsupported argument(s)\"\n\nFunction or method called with invalid argument(s) or parameter(s).\n\n* 1501 \"PRM - The key attribute is passed as an unsupported type\"\n\nThe \"key\" attribute is of an unsupported type.\n\n* 1502 \"PRM - The value attribute is passed without the key attribute\"\n\nThe \"value\" attribute is only allowed when a valid key is given.\n\n* 1503 \"PRM - The value attribute is passed as an unsupported type\"\n\nThe \"value\" attribute is of an unsupported type.\n\n* 2010 \"ECR - QUO char inside quotes followed by CR not part of EOL\"\n\nWhen \"eol\" has been set to anything but the default, like \"\\r\\t\\n\", and the \"\\r\" is following\nthe second (closing) \"quotechar\", where the characters following the \"\\r\" do not make up the\n\"eol\" sequence, this is an error.\n\n* 2011 \"ECR - Characters after end of quoted field\"\n\nSequences like \"1,foo,\"bar\"baz,22,1\" are not allowed. \"bar\" is a quoted field and after the\nclosing double-quote, there should be either a new-line sequence or a separation character.\n\n* 2012 \"EOF - End of data in parsing input stream\"\n\nSelf-explaining. End-of-file while inside parsing a stream. Can happen only when reading from\nstreams with \"getline\", as using \"parse\" is done on strings that are not required to have a\ntrailing \"eol\".\n\n* 2013 \"INI - Specification error for fragments RFC7111\"\n\nInvalid specification for URI \"fragment\" specification.\n\n* 2014 \"ENF - Inconsistent number of fields\"\n\nInconsistent number of fields under strict parsing.\n\n* 2021 \"EIQ - NL char inside quotes, binary off\"\n\nSequences like \"1,\"foo\\nbar\",22,1\" are allowed only when the binary option has been selected\nwith the constructor.\n\n* 2022 \"EIQ - CR char inside quotes, binary off\"\n\nSequences like \"1,\"foo\\rbar\",22,1\" are allowed only when the binary option has been selected\nwith the constructor.\n\n* 2023 \"EIQ - QUO character not allowed\"\n\nSequences like \"\"foo \"bar\" baz\",qu\" and \"2023,\",2008-04-05,\"Foo, Bar\",\\n\" will cause this\nerror.\n\n* 2024 \"EIQ - EOF cannot be escaped, not even inside quotes\"\n\nThe escape character is not allowed as last character in an input stream.\n\n* 2025 \"EIQ - Loose unescaped escape\"\n\nAn escape character should escape only characters that need escaping.\n\nAllowing the escape for other characters is possible with the attribute \"allowlooseescapes\".\n\n* 2026 \"EIQ - Binary character inside quoted field, binary off\"\n\nBinary characters are not allowed by default. Exceptions are fields that contain valid UTF-8,\nthat will automatically be upgraded if the content is valid UTF-8. Set \"binary\" to 1 to accept\nbinary data.\n\n* 2027 \"EIQ - Quoted field not terminated\"\n\nWhen parsing a field that started with a quotation character, the field is expected to be\nclosed with a quotation character. When the parsed line is exhausted before the quote is\nfound, that field is not terminated.\n\n* 2030 \"EIF - NL char inside unquoted verbatim, binary off\"\n\n* 2031 \"EIF - CR char is first char of field, not part of EOL\"\n\n* 2032 \"EIF - CR char inside unquoted, not part of EOL\"\n\n* 2034 \"EIF - Loose unescaped quote\"\n\n* 2035 \"EIF - Escaped EOF in unquoted field\"\n\n* 2036 \"EIF - ESC error\"\n\n* 2037 \"EIF - Binary character in unquoted field, binary off\"\n\n* 2110 \"ECB - Binary character in Combine, binary off\"\n\n* 2200 \"EIO - print to IO failed. See errno\"\n\n* 3001 \"EHR - Unsupported syntax for columnnames ()\"\n\n* 3002 \"EHR - getlinehr () called before columnnames ()\"\n\n* 3003 \"EHR - bindcolumns () and columnnames () fields count mismatch\"\n\n* 3004 \"EHR - bindcolumns () only accepts refs to scalars\"\n\n* 3006 \"EHR - bindcolumns () did not pass enough refs for parsed fields\"\n\n* 3007 \"EHR - bindcolumns needs refs to writable scalars\"\n\n* 3008 \"EHR - unexpected error in bound fields\"\n\n* 3009 \"EHR - printhr () called before columnnames ()\"\n\n* 3010 \"EHR - printhr () called with invalid arguments\"\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "IO::File, IO::Handle, IO::Wrap, Text::CSV, Text::CSVPP, Text::CSV::Encoded,\nText::CSV::Separator, Text::CSV::Slurp, Spreadsheet::CSV and Spreadsheet::Read, and of course\nperl.\n\nIf you are using Raku, have a look at \"Text::CSV\" in the Raku ecosystem, offering the same\nfeatures.\n\nnon-perl\nA CSV parser in JavaScript, also used by W3C <http://www.w3.org>, is the multi-threaded\nin-browser PapaParse <http://papaparse.com/>.\n\ncsvkit <http://csvkit.readthedocs.org> is a python CSV parsing toolkit.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Alan Citterman <alan@mfgrtl.com> wrote the original Perl module. Please don't send mail\nconcerning Text::CSVXS to Alan, who is not involved in the C/XS part that is now the main part\nof the module.\n\nJochen Wiedmann <joe@ispsoft.de> rewrote the en- and decoding in C by implementing a simple\nfinite-state machine. He added variable quote, escape and separator characters, the binary mode\nand the print and getline methods. See ChangeLog releases 0.10 through 0.23.\n\nH.Merijn Brand <h.m.brand@xs4all.nl> cleaned up the code, added the field flags methods, wrote\nthe major part of the test suite, completed the documentation, fixed most RT bugs, added all the\nallow flags and the \"csv\" function. See ChangeLog releases 0.25 and on.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright (C) 2007-2021 H.Merijn Brand.  All rights reserved.\nCopyright (C) 1998-2001 Jochen Wiedmann. All rights reserved.\nCopyright (C) 1997      Alan Citterman.  All rights reserved.\n\nThis library is free software; you can redistribute and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Text::CSVXS - comma-separated values manipulation routines",
    "flags": [],
    "examples": [
        "my $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });",
        "open my $fh, \"<\", \"file.csv\" or die \"file.csv: $!\";",
        "while (my $row = $csv->getline ($fh)) {",
        "# do something with @$row",
        "close $fh or die \"file.csv: $!\";",
        "or",
        "my $aoa = csv (in => \"file.csv\", onin => sub {",
        "# do something with %",
        "});",
        "Reading only a single column",
        "my $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });",
        "open my $fh, \"<\", \"file.csv\" or die \"file.csv: $!\";",
        "# get only the 4th column",
        "my @column = map { $->[3] } @{$csv->getlineall ($fh)};",
        "close $fh or die \"file.csv: $!\";",
        "with \"csv\", you could do",
        "my @column = map { $->[0] }",
        "@{csv (in => \"file.csv\", fragment => \"col=4\")};",
        "my $csv = Text::CSVXS->new ({ keepmetainfo => 1, binary => 1 });",
        "my $sampleinputstring =",
        "qq{\"I said, \"\"Hi!\"\"\",Yes,\"\",2.34,,\"1.09\",\"\\x{20ac}\",};",
        "if ($csv->parse ($sampleinputstring)) {",
        "my @field = $csv->fields;",
        "foreach my $col (0 .. $#field) {",
        "my $quo = $csv->isquoted ($col) ? $csv->{quotechar} : \"\";",
        "printf \"%2d: %s%s%s\\n\", $col, $quo, $field[$col], $quo;",
        "else {",
        "print STDERR \"parse () failed on argument: \",",
        "$csv->errorinput, \"\\n\";",
        "$csv->errordiag ();",
        "Parsing CSV from memory",
        "Given a complete CSV data-set in scalar $data, generate a list of lists to represent the rows",
        "and fields",
        "# The data",
        "my $data = join \"\\r\\n\" => map { join \",\" => 0 .. 5 } 0 .. 5;",
        "# in a loop",
        "my $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1 });",
        "open my $fh, \"<\", \\$data;",
        "my @foo;",
        "while (my $row = $csv->getline ($fh)) {",
        "push @foo, $row;",
        "close $fh;",
        "# a single call",
        "my $foo = csv (in => \\$data);",
        "The fast way: using \"print\"",
        "An example for creating \"CSV\" files using the \"print\" method:",
        "my $csv = Text::CSVXS->new ({ binary => 1, eol => $/ });",
        "open my $fh, \">\", \"foo.csv\" or die \"foo.csv: $!\";",
        "for (1 .. 10) {",
        "$csv->print ($fh, [ $, \"$\" ]) or $csv->errordiag;",
        "close $fh or die \"$tbl.csv: $!\";",
        "The slow way: using \"combine\" and \"string\"",
        "or using the slower \"combine\" and \"string\" methods:",
        "my $csv = Text::CSVXS->new;",
        "open my $csvfh, \">\", \"hello.csv\" or die \"hello.csv: $!\";",
        "my @sampleinputfields = (",
        "'You said, \"Hello!\"',   5.67,",
        "'\"Surely\"',   '',   '3.14159');",
        "if ($csv->combine (@sampleinputfields)) {",
        "print $csvfh $csv->string, \"\\n\";",
        "else {",
        "print \"combine () failed on argument: \",",
        "$csv->errorinput, \"\\n\";",
        "close $csvfh or die \"hello.csv: $!\";",
        "Generating CSV into memory",
        "Format a data-set (@foo) into a scalar value in memory ($data):",
        "# The data",
        "my @foo = map { [ 0 .. 5 ] } 0 .. 3;",
        "# in a loop",
        "my $csv = Text::CSVXS->new ({ binary => 1, autodiag => 1, eol => \"\\r\\n\" });",
        "open my $fh, \">\", \\my $data;",
        "$csv->print ($fh, $) for @foo;",
        "close $fh;",
        "# a single call",
        "csv (in => \\@foo, out => \\my $data);",
        "Rewrite \"CSV\" files with \";\" as separator character to well-formed \"CSV\":",
        "use Text::CSVXS qw( csv );",
        "csv (in => csv (in => \"bad.csv\", sepchar => \";\"), out => *STDOUT);",
        "As \"STDOUT\" is now default in \"csv\", a one-liner converting a UTF-16 CSV file with BOM and",
        "TAB-separation to valid UTF-8 CSV could be:",
        "$ perl -C3 -MText::CSVXS=csv -we\\",
        "'csv(in=>\"utf16tab.csv\",encoding=>\"utf16\",sep=>\"\\t\")' >utf8.csv",
        "Dumping a database table can be simple as this (TIMTOWTDI):",
        "my $dbh = DBI->connect (...);",
        "my $sql = \"select * from foo\";",
        "# using your own loop",
        "open my $fh, \">\", \"foo.csv\" or die \"foo.csv: $!\\n\";",
        "my $csv = Text::CSVXS->new ({ binary => 1, eol => \"\\r\\n\" });",
        "my $sth = $dbh->prepare ($sql); $sth->execute;",
        "$csv->print ($fh, $sth->{NAMElc});",
        "while (my $row = $sth->fetch) {",
        "$csv->print ($fh, $row);",
        "# using the csv function, all in memory",
        "csv (out => \"foo.csv\", in => $dbh->selectallarrayref ($sql));",
        "# using the csv function, streaming with callbacks",
        "my $sth = $dbh->prepare ($sql); $sth->execute;",
        "csv (out => \"foo.csv\", in => sub { $sth->fetch            });",
        "csv (out => \"foo.csv\", in => sub { $sth->fetchrowhashref });",
        "Note that this does not discriminate between \"empty\" values and NULL-values from the database,",
        "as both will be the same empty field in CSV. To enable distinction between the two, use",
        "\"quoteempty\".",
        "csv (out => \"foo.csv\", in => sub { $sth->fetch }, quoteempty => 1);",
        "If the database import utility supports special sequences to insert \"NULL\" values into the",
        "database, like MySQL/MariaDB supports \"\\N\", use a filter or a map",
        "csv (out => \"foo.csv\", in => sub { $sth->fetch },",
        "onin => sub { $ //= \"\\\\N\" for @{$[1]} });",
        "while (my $row = $sth->fetch) {",
        "$csv->print ($fh, [ map { $ // \"\\\\N\" } @$row ]);",
        "Note that this will not work as expected when choosing the backslash (\"\\\") as \"escapechar\", as",
        "that will cause the \"\\\" to need to be escaped by yet another \"\\\", which will cause the field to",
        "need quotation and thus ending up as \"\\\\N\" instead of \"\\N\". See also \"undefstr\".",
        "csv (out => \"foo.csv\", in => sub { $sth->fetch }, undefstr => \"\\\\N\");",
        "These special sequences are not recognized by Text::CSVXS on parsing the CSV generated like",
        "this, but map and filter are your friends again",
        "while (my $row = $csv->getline ($fh)) {",
        "$sth->execute (map { $ eq \"\\\\N\" ? undef : $ } @$row);",
        "csv (in => \"foo.csv\", filter => { 1 => sub {",
        "$sth->execute (map { $ eq \"\\\\N\" ? undef : $ } @{$[1]}); 0; }});",
        "use Text::CSVXS qw( csv );",
        "use JSON; # or Cpanel::JSON::XS for better performance",
        "# AoA (no header interpretation)",
        "say encodejson (csv (in => \"file.csv\"));",
        "# AoH (convert to structures)",
        "say encodejson (csv (in => \"file.csv\", bom => 1));",
        "Yes, it is that simple.",
        "For more extended examples, see the examples/ 1. sub-directory in the original distribution or",
        "the git repository 2.",
        "1. https://github.com/Tux/Text-CSVXS/tree/master/examples",
        "2. https://github.com/Tux/Text-CSVXS",
        "The following files can be found there:",
        "parser-xs.pl",
        "This can be used as a boilerplate to parse invalid \"CSV\" and parse beyond (expected) errors",
        "alternative to using the \"error\" callback.",
        "$ perl examples/parser-xs.pl bad.csv >good.csv",
        "csv-check",
        "This is a command-line tool that uses parser-xs.pl techniques to check the \"CSV\" file and",
        "report on its content.",
        "$ csv-check files/utf8.csv",
        "Checked files/utf8.csv  with csv-check 1.9",
        "using Text::CSVXS 1.32 with perl 5.26.0 and Unicode 9.0.0",
        "OK: rows: 1, columns: 2",
        "sep = <,>, quo = <\">, bin = <1>, eol = <\"\\n\">",
        "csv-split",
        "This command splits \"CSV\" files into smaller files, keeping (part of) the header. Options",
        "include maximum number of (data) rows per file and maximum number of columns per file or a",
        "combination of the two.",
        "csv2xls",
        "A script to convert \"CSV\" to Microsoft Excel (\"XLS\"). This requires extra modules Date::Calc",
        "and Spreadsheet::WriteExcel. The converter accepts various options and can produce UTF-8",
        "compliant Excel files.",
        "csv2xlsx",
        "A script to convert \"CSV\" to Microsoft Excel (\"XLSX\"). This requires the modules Date::Calc",
        "and Spreadsheet::Writer::XLSX. The converter does accept various options including merging",
        "several \"CSV\" files into a single Excel file.",
        "csvdiff",
        "A script that provides colorized diff on sorted CSV files, assuming first line is header and",
        "first field is the key. Output options include colorized ANSI escape codes or HTML.",
        "$ csvdiff --html --output=diff.html file1.csv file2.csv",
        "rewrite.pl",
        "A script to rewrite (in)valid CSV into valid CSV files. Script has options to generate",
        "confusing CSV files or CSV files that conform to Dutch MS-Excel exports (using \";\" as",
        "separation).",
        "Script - by default - honors BOM and auto-detects separation converting it to default standard",
        "CSV with \",\" as separator."
    ],
    "see_also": []
}