Created
January 7, 2014 06:57
-
-
Save artifactsauce/8295622 to your computer and use it in GitHub Desktop.
Convert from a Japanese encoding file to UTF-8.
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Encode; | |
use Encode::Guess qw/shift-jis euc-jp 7bit-jis/; | |
use Perl6::Slurp; | |
use Path::Class; | |
my $input = $ARGV[0]; | |
my $output = $ARGV[1] || $input; | |
my $body = slurp $input; | |
my $decoder = Encode::Guess->guess($body); | |
$body = $decoder->decode($body); | |
$body =~s/\r\n/\n/g; | |
my $file = file $output; | |
my $fh = $file->open('w') or die $!; | |
print $fh encode( 'utf-8', $body ); | |
$fh->close; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment