Categories
Perl

Perl Script Process a CSV File Line by Line

I use a program called jmemorize to assist with rote memorization. It’s pretty common to find a spreadsheet with a list of things you have to memorize, and jmemorize will allow to import CSV format if you add specific column headers.
The problem is wanting to format the questions and answers in a specific way, or add something on each line. Perl can process a file line by line and output it however you want. While the following Perl script probably won’t be used exactly like I used it – you can still benefit from processing files line by line. Here is how you open a file in Perl, process it line by line (instead of slurping the entire file inefficiently) and modify each line as you go: