Decided to try and learn Perl, and currently need to process a number of CSV files.
To get started doing more advance text manipulation I first need a base code that:
- Imports a local CSV
- Does a basic text manipulation
- Save the resulting changed values
The import/process/export should support 1000+ rows and 20+ columns. Going to supplies a sample CSV file, but feel free to supply one in your answer.
SAMPLE CSV FILE:
"EmployeeName","OfficeHistory","JobLevelHistory"
"John Smith",501,"Engineer"
"John Smith",601,"Senior Engineer"
"John Smith",701,"Manager"
"Alex Button",601,"Senior Assistant"
"Alex Button",454,"Manager"
If you have any questions, let me know — this will be a HUGE help in me getting started. My main focus is the text manipulation, but the manipulations are meaningless unless I’ve got a way to input data and export it back to a file. Also, if you have any suggestion for quickly creating and debugging text manipulations that would be a huge help too. (NOTE: Currently use an application to do this, but need more control, and decided to give Perl a try.)
Use Text::CSV_XS or Text::CSV.
Anything else will drive you insane, sooner or later. CSV is an unruly format in practice, though there are rules laid down (RFC 4180) but they were defined somewhat post hoc so some systems, notably by Microsoft, handle them differently. MS did indeed get there first, but there are differences between the CSV formats recognized by different MS products.
Rehash of Text::CSV manual page
Output based on your sample data