in reply to Re: Question about parsing columns when using Text::CSV
in thread Question about parsing columns when using Text::CSV

Greetings. What exactly is wrong with using the diamond operator here? What specifically makes it unsafe, and why is using your method considered "better defense?" Thanks.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on Re^2: Question about parsing columns when using Text::CSV

Replies are listed 'Best First'.
Re^3: Question about parsing columns when using Text::CSV
by Tux (Canon) on Jan 07, 2009 at 09:42 UTC

    Short answer: nested newlines

    Longer answer: Though in the case of the OP, there are no embedded newlines or other binary characters, it's just waiting for it to happen one day or another when new fields are added to the end. CSV is safe and defined enough to cope, but if the diamond is used to read CSV (in general), all lines that have embedded newlines will cause the CSV parsing to fail from that point on.

    Note that the $csv->getline () will use the diamond (CORE's getline ()) internally too, but Text::CSV (and Text::CSV_XS and Text::CSV_PP) will know internally that the line might not be finished and will correct that on a need-to-be basis.

    Another reason to use getline () instead of diamond, is that the getline () is magnitudes faster than the combination of diamond + parse (), even when using Text::CSV_PP.


    Enjoy, Have FUN! H.Merijn