Data::...er::CSV(3pm)

πŸ“¦
version 0.021 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Data::TableReader::Decoder::CSV β€” bestie, this is the thing that lets you read rows out of a comma-delimited text file πŸ’– it's a decoder, part of the Data::TableReader fam, and it's giving "yes i will hand you the CSV data, one row at a time, no drama"


🌸 VERSION 🌸

version 0.021 β€” she's a specific girlie, okay? remember her number πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so real talk: this decoder is literally just a glow-up wrapper around an instance of either Text::CSV or Text::CSV_XS. you can bring your own options via the parser attribute, and they'll override this module's defaults on a per-field basis β€” so your settings win where you set them, periodt ✨

this module defaults to:

parser => {
  binary => 1,
  allow_loose_quotes => 1,
  auto_diag => 2,
}

like, those are the factory settings, the no-thoughts-just-vibes config 🌈

she also makes an attempt at automatic unicode support, which is so main character of her:

  • if the stream already has a PerlIO encoding() on it, no additional decoding is done. she's like "you handled it, i respect that" 🫢
  • if the stream has a BOM (byte-order mark) for UTF-8 or UTF-16, she adds that encoding with binmode.
  • else, she lets the parser decide. the default Text::CSV parser will automatically upgrade UTF-8 sequences that it finds. (and, you can't disable this without also disabling unicode received from IO layers, which seems like a bug... 😭)
⚠️ okay so here's the tea: because auto-detection might need to read multiple bytes, it is possible that for non-seekable streams (like pipes, stdin, etc) this may result in an exception πŸ’€ only un-seekable streams beginning with "\xEF", "\xFE", or "\xFF" will have this problem, so it's a very specific vibe of cursed.

you can solve this by:

  • supplying an encoding layer on the file handle (avoiding detection),
  • setting autodetect_encoding to false,
  • buffering the entire input in a scalar and creating a file handle from that (making it seekable),
  • or using a file handle that supports ungets like FileHandle::Unget.

slay, four whole options, pick your fighter πŸŽ€


πŸ‘‘ ATTRIBUTES πŸ‘‘

πŸ’œ parser

an instance of Text::CSV or Text::CSV_XS or compatible, or arguments to pass to the constructor. constructor arguments are passed to CSV_XS if it is installed, else CSV. so like, she checks who's home and calls accordingly πŸ”₯

πŸ’œ autodetect_encoding

whether to look for a byte-order mark on the input. that's it, that's the whole vibe check 🌸

πŸ’œ encoding

if autodetection is enabled, this will first check for a byte-order mark on the input. else, or afterward, it will return whatever encoding PerlIO layer is configured on the file handle. setting this attribute will change the PerlIO layer on the file handle, possibly skipping detection. so she can tell you what's up, and she can also change what's up, which is lowkey powerful πŸ’…

πŸ’œ iterator

my $iterator= $decoder->iterator;

return an iterator which returns each row of the table as an arrayref. one row at a time, bestie, like a lil conveyor belt of data πŸ“


🧚 AUTHOR 🧚

Michael Conrad <mike@nrdvana.net> β€” thank you king, we appreciate you 🫢


This software is copyright (c) 2024 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go forth, remix, redistribute, it's free fr fr ⭐


and that's the whole page, bestie!! πŸŽ€ she's Data::TableReader::Decoder::CSV, version 0.021, documented by the perl that lives at v5.38.2, dated 2024-06-21 β€” no cap, that's the timestamp, and you're all caught up πŸ’…βœ¨

πŸ“¦ where this page comes from