<commit_before>#!/usr/bin/env perl

use File::Spec;
use Getopt::Long;
use Spreadsheet::XLSX;
use Text::CSV;
use Text::Iconv;

package CSVWriter;

sub new {
  my $class = shift;
  my $path = shift;
  my $csv = Text::CSV->new({binary=>1, eol=>$\})
    or die "Text::CSV->new() failed: " . Text::CSV->error_diag();
  my $file_handle;
  my $eol = "\n";

  open $file_handle, ">:encoding(utf8)", $path
    or die "could not open $path for wrtiting: $!";

  my $self = {path=>$path,
              csv=>$csv,
              file_handle=>$file_handle,
              eol=>$eol};

  bless $self, $class;
  $self;
}

sub print_row {
  my $self = shift;
  my $arrayref = shift;

  $self->{csv}->print($self->{file_handle}, $arrayref)
    or die "CSV write failure";<commit_msg>fix typo in xlsx-to-csv error msg<commit_after>#!/usr/bin/env perl

use File::Spec;
use Getopt::Long;
use Spreadsheet::XLSX;
use Text::CSV;
use Text::Iconv;

package CSVWriter;

sub new {
  my $class = shift;
  my $path = shift;
  my $csv = Text::CSV->new({binary=>1, eol=>$\})
    or die "Text::CSV->new() failed: " . Text::CSV->error_diag();
  my $file_handle;
  my $eol = "\n";

  open $file_handle, ">:encoding(utf8)", $path
    or die "could not open $path for writing: $!";

  my $self = {path=>$path,
              csv=>$csv,
              file_handle=>$file_handle,
              eol=>$eol};

  bless $self, $class;
  $self;
}

sub print_row {
  my $self = shift;
  my $arrayref = shift;

  $self->{csv}->print($self->{file_handle}, $arrayref)
    or die "CSV write failure";
{'fraction_non_alphanumeric': 0.18616677440206852, 'fraction_numerical': 0.002585649644473174, 'mean_word_length': 3.1390374331550803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6386845', 'n_tokens_mistral': 611, 'n_tokens_neox': 595, 'n_words': 150}