Camelia
Prev: Command line options

Process CSV file

examples/arrays/sample_csv_file.csv
Foo,Bar,10,home
Orgo,Morgo,7,away
Big,Shrek,100,US
Small,Fiona,9,tower
examples/arrays/process_csv_file.p6
#!/usr/bin/env perl6
use v6;

my $file = 'examples/arrays/sample_csv_file.csv';
if defined @*ARGS[0] {
    $file = @*ARGS[0];
}

my $sum = 0;
my $data = open $file;
for $data.lines -> $line {
    my @columns = split ",", $line;
    $sum += @columns[2];
}
say $sum;


Prev: Command line options

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: