Skip to content

Instantly share code, notes, and snippets.

@artifactsauce
Created January 7, 2014 06:57
Show Gist options
  • Save artifactsauce/8295622 to your computer and use it in GitHub Desktop.
Save artifactsauce/8295622 to your computer and use it in GitHub Desktop.
Convert from a Japanese encoding file to UTF-8.
#!/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