Exercise: Add numbers taken from a CSV file
Given a CSV file like this:
examples/data/process_csv_file.csv
Tudor;Vidor;10;Hapci Szundi;Morgo;7;Szende Kuka;Hofeherke;100;Kiralyno Boszorkany;Herceg;9;Meselo
Write a script that will take the values of the 3rd in this Comma Separated Values file and add them together.
Can your code also handle this file?
examples/data/distance.csv
Budapest,Bukarest,1200,km Tel Aviv,Beirut,500,km London,Dublin,300,km New York,"Moscow, East",6000,km Local,"Remote Location",10,km
Tools
Solutions in Perl 5
- Perl 5 Process CSV file
- Perl 5 Process CSV file short version
- Perl 5 One-liner sum of column in CSV
- Process CSV file using Text::CSV_XS
Solution Ruby
Solution in Groovy
Published on 2015-11-02
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post