Data::...iotCSV(3pm)

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

πŸ‘‘ NAME πŸ‘‘

Data::TableReader::Decoder::IdiotCSV β€” bestie, this is the decoder that lets you actually read the rows of a badly formatted comma-delimited text file. Yes. That kind of badly. We'll get to it. πŸ’…

(You'll see it hanging out in the manual as Data::...iotCSV(3pm) because even the manpage header is a little extra, and honestly? Respect. πŸŽ€)


✨ VERSION ✨

version 0.021 β€” she's little, she's fierce, she's numbered. 🌸


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so picture this: this decoder is basically ::Decoder::CSV's cooler cousin. Same energy, but she can additionally parse the absolute garbage that happens when certain special little individuals write their very own "CSV Export" code. You know the type. It looks like this:

print join(",", map qq{"$_"}, @record)."\n";

(or, let's be honest, it's the Visual Basic or PHP equivalent, because that's almost definitely what they're using πŸ™ˆ) and the code does that regardless of whether their data happens to contain quote characters or newlines. Which it does. It always does. So you end up with hot mess like:

"First Name","Last Name","email"
"Joseph "Joe","Smith",""Smith, Joe" <jsmith@example.com>"

Not me getting a migraine just looking at it 😭

The good news? Recent versions of the Text::CSV module can actually process this. You just have to hit it with this exact configuration:

{
  binary => 1,
  allow_loose_quotes => 1,
  allow_whitespace => 1,
  escape_char => undef,
}

So this module is literally just a subclass of Data::TableReader::Decoder::CSV that hands those defaults straight to the parser. That's it. That's the whole trick. Slay. ✨

But how does the parsing actually work, you ask? Guessing. Patterns. Vibes. 🧚 It is not super reliable, and no cap on that one. You should always complain loudly to whoever generated that data β€” unless they're a much larger company than you and would simply never listen, or they went out of business a while back, in which case, bestie, you are fully justified in using this module in production. πŸ’–

Real talk: this is a rescue mission, not a flex. Complain first. Ship second. 🫢

πŸ’œ AUTHOR πŸ’œ

Michael Conrad <mike@nrdvana.net> β€” the icon who looked at the garbage and said "fine, I'll handle it." πŸ‘‘


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.


Okay that's the whole page, bestie!! 🌸 This was User Contributed Perl Documentation energy, built for perl v5.38.2, dated 2024-06-21 β€” go forth, parse the garbage, and text me when it works πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from