Skip to content

Instantly share code, notes, and snippets.

@Tux
Created February 4, 2015 08:22
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/6520a23f118908ae8237 to your computer and use it in GitHub Desktop.
Save Tux/6520a23f118908ae8237 to your computer and use it in GitHub Desktop.
#!perl6
use v6;
use Slang::Tuxic;
use Inline::Perl5;
my $p5 = Inline::Perl5.new;
$p5.use ("Text::CSV_XS");
my @rows;
my $csv = $p5.invoke ("Text::CSV_XS", "new")
or die "Cannot use CSV: ", $p5.invoke ("Text::CSV", "error_diag");
$csv.binary (1);
$csv.auto_diag (1);
my Int $sum = 0;
for lines () :eager {
$csv.parse ($_);
$sum += $csv.fields.elems;
}
$sum.say;
=>
csv-easy-xs 50000 0.021
csv-easy-pp 50000 0.019
csv-test-xs 50000 0.039
csv-test-pp 50000 0.520
csv-pegex 50000 1.371
csv 50000 8.268
csv-ip5xs 50000 9.257 <===
csv_gram *** 60000 13.843
test 50000 40.042
test-x 50000 42.783
What I really would like to see is (pseudo-syntax)
my Int $sum = 0;
while (my $row = $csv.getline (*ARGV)) {
$sum += +(@$row);
}
$sum.say;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment