Created
May 28, 2014 09:05
-
-
Save hisaichi5518/03957bd6c44057cc6297 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use 5.10.1; | |
| use strict; | |
| use warnings; | |
| use Text::CSV; | |
| use Text::CSV_XS; | |
| use Encode; | |
| my $csv = Text::CSV->new ({ binary => 1 }); | |
| my $xs = Text::CSV_XS->new({ binary => 1 }); | |
| my $nb_csv = Text::CSV->new ({ binary => 0 }); | |
| my $nb_xs = Text::CSV_XS->new({ binary => 0 }); | |
| sub parse { | |
| my ($driver, $body) = @_; | |
| my $encoded_body = encode_utf8 $body; | |
| warn $encoded_body; | |
| open my $fh, '<', \$encoded_body or die "Cant open body: $!"; | |
| my $rows = $driver->getline_all($fh); | |
| close $fh or die "Cant close body: $!"; | |
| $rows; | |
| } | |
| use Encode; | |
| { | |
| warn "テキスト文字列で渡す"; | |
| my $result = parse($csv, decode_utf8 "test,test\n1,日本語"); | |
| warn Encode::is_utf8($result->[1][1]); # 1が返ってくる | |
| warn $result->[1][1]; # Wideなんちゃらがでる | |
| }; | |
| { | |
| warn "バイト文字列で渡す"; | |
| my $result = parse($csv, "test,test\n1,日本語"); | |
| warn Encode::is_utf8($result->[1][1]); # なぜか1が返ってくる | |
| warn $result->[1][1]; # Wide なんちゃらは出ない | |
| }; | |
| { | |
| warn "テキスト文字列で渡す"; | |
| my $result = parse($xs, decode_utf8 "test,test\n1,日本語"); | |
| warn Encode::is_utf8($result->[1][1]); # 1が返ってくる | |
| warn $result->[1][1]; # Wideなんちゃらがでる | |
| }; | |
| { | |
| warn "バイト文字列で渡す"; | |
| my $result = parse($xs, "test,test\n1,日本語"); | |
| warn Encode::is_utf8($result->[1][1]); # なぜか1が返ってくる | |
| warn $result->[1][1]; # Wide なんちゃらは出ない | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment