473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems in comparing two files written in Japanese

1
Hi,

I got the code (from the internet)for comparing two files and showing the difference in contents.Now,I tried the same code for two files written in japanese language(kanji).If I save the two japanese .txt files in ANSI format,it works fine,but, if I save them in formats like 'UTF-8','unicode','unicode bigendian',it doesn't show the differences properly....keeps showing odd symbols instead of the japanese characters.

Would be glad if someone could suggest some simple way of making it work for all formats.

The code I am using is the one pasted below:



Expand|Select|Wrap|Line Numbers
  1. #!C:\perl\bin\perl.exe
  2. # file_compare.pl
  3. # Purpose: compare two files(file_1,file_2) and show differences
  4.  
  5.  
  6. use strict;
  7. use warnings;
  8.  
  9. my $file1 ='E:\perl_folder\file_1.txt' or die "filename missing \n";
  10. my $file2 ='E:\perl_folder\file_2.txt'  or die "filename missing \n";
  11.  
  12. open (FILE1, "< $file1") or die "Can not read file $file1: $! \n";
  13. my @file1_contents = <FILE1>; # read entire contents of file
  14. close (FILE1);
  15.  
  16. open (FILE2, "< $file2") or die "Can not read file $file2: $! \n";
  17. my @file2_contents = <FILE2>; # read entire contents of file
  18. close (FILE2);
  19.  
  20. my $length1 = $#file1_contents; # number of lines in first file
  21. my $length2 = $#file2_contents; # number of lines in second file
  22.  
  23. if ($length1 > $length2) {
  24. # first file contains more lines than second file
  25. my $counter2 = 0;
  26. foreach my $line_file1 (@file1_contents) {
  27. chomp ($line_file1);
  28.  
  29. if (defined ($file2_contents[$counter2])) {
  30. # line exists in second file
  31. chomp (my $line_file2 = $file2_contents[$counter2]);
  32.  
  33. if ($line_file1 ne $line_file2) {
  34. print "\nline " . ($counter2 + 1) . " \n";
  35. print "< $line_file1 \n" if ($line_file1 ne ""); 
  36. print "--- \n";
  37. print "> $line_file2 \n\n" if ($line_file2 ne "");
  38. }
  39. }
  40. else {
  41. # there is no line in second file
  42. print "\nline " . ($counter2 + 1) . " \n";
  43. print "< $line_file1 \n" if ($line_file1 ne ""); 
  44. print "--- \n";
  45. print "> \n"; # this line does not exist in file2
  46. }
  47. $counter2++; # point to the next line in file2
  48. }
  49. }
  50.  
Jul 16 '09 #1
1 2307
KevinADC
4,059 Expert 2GB
if you get no replies here try on www.perlmonks.com or www.stackoverflow.com

I personally don't know how to do what you are asking.
Jul 16 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: HerrLucifer | last post by:
I am each day becoming more and more addicted to the new .Net framework because of its cool RAD facilities. However, performance and speed is extremely important for my application development. I...
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
21
by: Doug Lerner | last post by:
I'm working on a client/server app that seems to work fine in OS Firefox and Windows IE and Firefox. However, in OS X Safari, although the UI/communications themselves work fine, if the...
2
by: DragonShade | last post by:
To be honest, I'm not sure if this is a .NET issue, some configuration on a PC, or a setting in a database but here goes: Environment (have NO control over): XP (London & Tokyo),.NET 2.0 C#, 2...
9
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links....
3
bigturtle
by: bigturtle | last post by:
Is it possible to translate a program having some original-language material hard-coded in the original code? My client is Dr. S, a medical doctor from Japan specializing in occupational health,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.