Inline::Perl5 now supports passing IO (including deep and dark IO from within XS), so this code works:
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_XS", "error_diag
+");
$csv.binary (1);
$csv.auto_diag (1);
my $fh = open "/tmp/hello.csv", :r, chomp => False;
my Int $sum = 0;
while (my $r = $csv.getline ($fh)) {
$sum += +$r;
}
$sum.say;
To give an example of performance (seconds needed to parse 10000 lines of 5 fields each). Note that Text::CSV::Easy_* only accepts valid CSV and has no options.
When I started in october 2014, the Regex based solution took 260 seconds, so improvement in the language itself is made on a daily basis!
Enjoy, Have FUN! H.Merijn