Skip to content

Instantly share code, notes, and snippets.

@mbajur
Created December 17, 2013 21:15
Show Gist options
  • Save mbajur/8012739 to your computer and use it in GitHub Desktop.
Save mbajur/8012739 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Encode qw( decode FB_QUIET );
binmode STDIN, ':bytes';
binmode STDOUT, ':encoding(UTF-8)';
my $out;
while ( <> ) {
$out = '';
while ( length ) {
# consume input string up to the first UTF-8 decode error
$out .= decode( "utf-8", $_, FB_QUIET );
# consume one character; all octets are valid Latin-1
$out .= decode( "iso-8859-1", substr( $_, 0, 1 ), FB_QUIET ) if length;
}
print $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment