# No.68 Perl Sample (code key - 15) # Unicode: Processing Japanese files (日本語の文字を処理する) # Tomonori Nagano # Last Update: January 18, 2008 # # This file is encoded in Unicode (UTF-8). If you see gibberish characters, # please re-encode the file in utf-8. # # Open INFILE with EUC-JP and output in Shift JIS # use 'uft8' to convert a file into Unicode # open INFILE, "<:encoding(euc-jp)", $infile_path or die "Cannot open the infile: $!\n" ;; open OUTFILE, ">:encoding(shift_jis)", $outfile_path or die "Cannot open the outfile: $!\n" ; # The same thing with "from_to" # use 'uft8' to convert a file into Unicode # use Encode qw(from_to) ; open INFILE, "<", $infile_path or die "Cannot open the infile: $!\n" ;; open OUTFILE, ">", $outfile_path or die "Cannot open the outfile: $!\n" ; while (){ from_to($_,"euc-jp","shift_jis") ; print OUTFILE $_ ; } # still the same thing with encoding # use 'uft8' to convert a file into Unicode # use encoding 'euc-jp', STDOUT => 'shift_jis' ; while (<>) { print $_ ; }