How to convert half width Japanese character including hyphen to full width in perl cgi?

Viewed 74

I have a list of CSV outputs of students' information.

    my $SrchResult = $TextBookCommonAdmin->GetOrderCSV($SrchData);

my $CsvData = '"受付番号","学籍番号","氏名","フリガナ","〒","都道府県・市区","町村・番地","アパート・マンション名"' . "\r\n";

    foreach my $DataId (sort (keys %{$SrchResult})){
         
            
        foreach my $key (keys %{$DataHash}){
            $DataHash->{$key} = decode('utf8',$DataHash->{$key});
        }
        my $LineData    = sprintf('"%s","%s","%s","%s","%s","%s","%s","%s"',
                            $DataHash->{'recptid'},
                            $DataHash->{'student_id'},
                            $DataHash->{'student_name'},
                            $DataHash->{'student_kana'},
                            $DataHash->{'student_zip'},
                            $DataHash->{'student_address'},
                            $DataHash->{'student_address2'},
                            $DataHash->{'student_address3'},
                    );

        $CsvData    .= sprintf("%s\r\n", $LineData);
    }

my ($second, $minute, $hour, $day, $month, $year, @rest) = localtime(); 
$year       += 1900;
$month      += 1;   
my $TimeStr = sprintf('%4d-%02d-%02d', $year, $month, $day);
my $TimedateFormat  = sprintf('%4d%02d%02d%02d%02d%02d', $year, $month, $day, $hour, $minute, $second);

my $name= $TimedateFormat.".csv";

print "Content-Type: application/octet-stream\n";
print "Content-Disposition: attachment; filename=$name\n\n";
print encode('cp932', $CsvData);

input data : 86 | 20A1123032C | 内村 颯太 | ウチムラ ソウタ | 2130013 | 神奈川県 | 2-9-4 | スペランサ4-2-9

output csv : 86 | 20A1123032C | 内村 颯太 | ウチムラ ソウタ | 2130013 | 神奈川県 | 2002/9/4 | スペランサ4?2?9

example above: When opened Perl CSV file, hyphenated numbers are converted to date and hyphenated text are converted to ? in the 'student_address2' & 'student_address3'column.

Maybe there is a case of Japanese Hankaku (Half-width) and Zankaku(Full-width) problem.

Is there any solution to sort it out?

0 Answers
Related