use utf8;
binmode STDIN, ':encoding(cp932)';
binmode STDOUT, ':encoding(cp932)';
binmode STDERR, ':encoding(cp932)';
use utf8;
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
sub read_file{
my($file, $enc) = @_;
if (!open(FH, "<:$enc", $file)){
die("error :$!");
}
my @ret_list = ();
while(<FH>){
my $line = $_;
chomp($line);
push(@ret_list, $line);
}
close(FH);
return @ret_list;
}
sub write_file{
my ($file, $list_ref, $enc) = @_;
if (!open(WFH, ">:$enc", "$file")){
die("error :$!");
}
foreach my $line (@{$list_ref}){
print WFH "$line\n"
}
close(WFH);
}
my @lines = read_file("test.data", "utf8");
foreach my $line (@lines){
print( $line."\n" );
my @datas = split(/,/, $line);
foreach my $data (@datas){
print($data."\n");
}
}
write_file("output.txt", \@lines, "utf8");