#!/usr/bin/perl -w %encodings=("-euc" => "euc-jp", "-euc-jp" => "euc-jp", "-sjis" => "shiftjis", "-iso7" => "iso-2022-jp", "-utf7" => "utf7", "-utf8" => "utf8", "-hz" => "hz", "-gb-raw" => "gb2312-raw", "-euc-cn" => "euc-cn", "-big5" => "big5-eten"); sub help { $options=join("\n",keys %encodings); print "jencode option infile option outfile\n\n", "Converts Japanese (or Chinese) text files between character ", "encodings.\n\n"; print "options are:\n${options}\n\n"; exit; } sub check { for(keys %encodings){ return $encodings{$_} if $_[0]=~/^${_}$/; } die("Invalid encoding. $_[0] not supported.\n"); } help unless @ARGV==4; $input_encoding=$ARGV[0]; $input_encoding=check($input_encoding); $input_file=$ARGV[1]; $output_encoding=$ARGV[2]; $output_encoding=check($output_encoding); $output_file=$ARGV[3]; open(IN,"<:encoding(${input_encoding})","${input_file}") or die("Can't open ${input_file}: $!\n"); open(OUT,">:encoding(${output_encoding})","${output_file}") or die("Can't open ${output_file}: $!\n"); print OUT ; close IN; close OUT;