Created
April 7, 2015 06:56
-
-
Save Tux/11686e410ea6418b465a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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