in reply to How to add a new column into my csv file?

Stop using split, install Text::CSV and/or Text::CSV_XS and read their docs.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: How to add a new column into my csv file?
by chaney123 (Acolyte) on Sep 07, 2017 at 08:17 UTC
    Hi,

    Thanks for the suggestion but may I know what's the reason behind it? Is split not efficient? Sorry, I just started to learn Perl few weeks ago.

      what's the reason behind it?

      The modules will handle any complications: embedded separation characters, quoting rules, missing columns, character encoding, EOL issues, etc. split will simply split a string into a list which is fine for trivial, well-formed in-memory CSV datasets. To go beyond such datasets would be tortuous without using Text::CSV_XS et al.

      It is the same reason why you would not be recommended to use regular expressions to parse any but the most trivial XML sets, for example.

      Update: (edited for typo)