473,242 Members | 1,500 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,242 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 2295
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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.