# open_pragma.pl
# 内容 : openプラグマによって、文字コードの変換を行う
# Copyright (c) 2011 Mitsuo Minagawa, All rights reserved.
# (minagawa@fb3.so-net.ne.jp)
# 使用方法 : c:\>open_pragma.pl
#

use open IN  => ":encoding(utf8)";
use open OUT => ":encoding(windows-31j)";

open(IN1, "input_utf8.txt");
open(OUT1, ">output.txt");

while	($line1	=	<IN1>)	{
	chomp($line1);

# CSV形式の $line1 から値を取り出して @in1 に入れる

	my $tmp	=	$line1;
	$tmp	=~	s/(?:\x0D\x0A|[\x0D\x0A])?$/,/;
	@in1	=	map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}
			($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);

	$out1	=	join("\t",@in1);
	print	OUT1	"$out1\n";
}

close(IN1);
close(OUT1);
