How can I parse quoted CSV in Perl with a regex?

前端 未结 7 1455
青春惊慌失措
青春惊慌失措 2020-11-30 09:10

I\'m having some issues with parsing CSV data with quotes. My main problem is with quotes within a field. In the following example lines 1 - 4 work correctly but 5,6 and 7 d

7条回答
  •  执念已碎
    2020-11-30 09:35

    Please, Try Using CPAN

    There's no reason you couldn't download a copy of Text::CSV, or any other non-XS based implementation of a CSV parser and install it in your local directory, or in a lib/ sub directory of your project so its installed along with your projects rollout.

    If you can't store text files in your project, then I'm wondering how it is you are coding your project.

    http://novosial.org/perl/life-with-cpan/non-root/

    Should be a good guide on how to get these into a working state locally.

    Not using CPAN is really a recipe for disaster.

    Please consider this before trying to write your own CSV implementation.

    Text::CSV is over a hundred lines of code, including fixed bugs and edge cases, and re-writing this from scratch will just make you learn how awful CSV can be the hard way.

    note: I learnt this the hard way. Took me a full day to get a working CSV parser in PHP before I discovered an inbuilt one had been added in a later version. It really is something awful.

提交回复
热议问题