#!/usr/bin/env/perl use strict; use warnings; use utf8; use Encode qw (:DEFAULT is_utf8); my %encodings = ( CP924 => "ibm-924_P100-1998", # more encodings here ); exit 0 unless @ARGV; foreach my $enc_file ( @ARGV ) { next if $enc_file eq "decode_it.pl"; next if $enc_file eq "encode_it.pl"; next if $enc_file eq "generate_charmap_for_testing.pl"; unless ( $encodings{$enc_file} ) { print "No valid encoding definition for $enc_file\n"; next; } my $module = "Encode::".$enc_file; eval{ (my $file = $module) =~ s|::|/|g; require $file.'.pm'; $module->import(); 1; } or do { print "$module not found\n"; next; }; open( my $fh_in, '<', $enc_file) or next; my $filecontent = do{ local $/ = undef; # input record separator undefined <$fh_in> }; my $content; eval{ $content = decode ( $encodings{$enc_file}, $filecontent ); }; if ( $@ ){ print $@,"skipping encoding\n"; next; } my $encoded_content = encode ( $encodings{$enc_file}, $content ); my $decoded_content = decode ( $encodings{$enc_file}, $encoded_content ); if ( $decoded_content eq $content ) { print "Encoding $enc_file is working properly\n"; } else { print "Encoding $enc_file produces errors\n"; } }