Skip to content

Instantly share code, notes, and snippets.

@Tux
Created April 7, 2015 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tux/11686e410ea6418b465a to your computer and use it in GitHub Desktop.
Save Tux/11686e410ea6418b465a to your computer and use it in GitHub Desktop.
#!perl6
use v6;
use Slang::Tuxic;
use Text::CSV;
sub MAIN (:$getline, :$getline_all) {
my $csv = Text::CSV.new;
my Int $sum = 0;
if ($getline_all) { # slowest
$sum = [+] $csv.getline_all ($*IN)».map(*.elems);
}
elsif ($getline) { # middle, but safe
while ($csv.getline ($*IN)) {
$sum += $csv.fields.elems;
}
}
else { # fastest, but unsafe
for lines () :eager {
$csv.parse ($_);
$sum += $csv.fields.elems;
}
}
$sum.say;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment