On 14/01/16 08:15, H.Merijn Brand wrote:
Here's an example of ported DBI code:
--8<---
#!perl6

use v6;
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 Int $sum = 0;
for lines() {
     $csv.parse($_);
     $sum += $csv.fields.elems;
     }
$sum.say;
-->8---

Please note, that the code could be a bit simpler:

    use v6;
    use Text::CSV_XS:from<Perl5>;
my $csv = Text::CSV_XS.new() or die "Cannot use CSV: " ~ Text::CSV_XS.error_diag();
    [...]

That should work. For more information, see the Readme of Inline::Perl5, which also has a whole bunch of examples.

Regards
  - Timo

Reply via email to