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


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
  6. use strict;
  7. use warnings;
  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";
  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);
  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);
  20. my $length1 = $#file1_contents; # number of lines in first file
  21. my $length2 = $#file2_contents; # number of lines in second file
  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);
  29. if (defined ($file2_contents[$counter2])) {
  30. # line exists in second file
  31. chomp (my $line_file2 = $file2_contents[$counter2]);
  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. }
Jul 16 '09 #1
1 2295
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

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...
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...
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...
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...
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...
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....
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,...
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...
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...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
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...
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"....
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...
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...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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.