1. Perl
  2. Module
  3. Text::CSV::Encoded

Text::CSV::Encoded - Handle CSV files containing Japanese

Use the Text::CSV::Encoded module to work with CSV files containing Japanese. Below is an example that processes CSV. Save the script in UTF-8.

use strict;
use warnings;
use utf8;

use Text::CSV::Encoded;

my $file = shift;

my $encoding = 'UTF-8';
my $csv = Text::CSV::Encoded->new({{
  encoding_in => $encoding,
  encoding_out => $encoding
});

open my $fh, "<", $file
  or die "Can't open $file:$!";

while (my $fields = $csv->getline($fh)) {

  # Edit data (here, put the word edit in the first field)
  $fields->[0]. = 'Edit';
  
  # Output field data
  $csv->print(* STDOUT, $fields);
  
  # Output a line break
  print "\n";
}

while statement is used to read the lines of the CSV file line by line.

Related Informatrion