stavan2003 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get diff of two .slk files. For which I am reading the slk file and putting them into an array in the required format. After that I am using the Text::Diff module to get the difference.

sub ReadFileToArray($@) { ($fileName,$NotFormattedFile) = @_; @LineContents = (); @contents_Array = (); $Line = ""; $var = '"'; open (MyFileHandle,"$fileName") or die("File Not Found"); while($Line=readline(MyFileHandle)){ push (@$NotFormattedFile,$Line); $Line =~ s/$var//g; @LineContents = $Line; if($Line =~ m/^C;/i) { $Line =~ s/K/ / ; @LineContents = split(';',$Line); shift(@LineContents); shift(@LineContents); shift(@LineContents); } push (@contents_Array,@LineContents); } close (MyFileHandle); return @contents_Array; } @File1 = ReadFileToArray("$path1"."\\1.slk",\@File1_NotFormat); $s1 = @File1; @File2 = ReadFileToArray("$path2"."2.slk",\@File2_NotFormat); open (MYFILE1, ">>C:\\1_ERROR.txt"); print MYFILE1 @File1; open (MYFILE2, ">>C:\\2_ERROR.txt"); print MYFILE2 @File1; $Textdiff = diff \@File1, \@File2; print $Textdiff;

It seems to work for most of the files except for some, where i get the size of the array ($s1) to be 21737. Also the complete array is not writted to the file and then the Text::Diff seems to get stuck.Don't know if its a memory problem or some other issue...?

Replies are listed 'Best First'.
Re: Text:Diff seems to get stuck
by Khen1950fx (Canon) on May 01, 2010 at 03:47 UTC
    I tried to replicate the problem with Text::Diff, but I couldn't get it to hang. I tried with a couple of large files and a couple of small SLK files. Maybe you might have better luck if you choose a style. I went with "OldStyle" here:
    #!/usr/bin/perl use strict; use warnings; use Text::Diff; my @seq1 = 'ID;P P;PGeneral C;Y1;X1;K"Row 1 Left Justify" F;P0;FG0L C;Y2;X1;K"Row 2 Right Justify" F;P0;FG0R C;Y3;X1;K"Total at Center" F;P0;FG0C C;Y1;X2;K11 C;Y2;X2;K22 C;Y3;X2;K0;ER1C2+R2C2 F;Y1;X2;FF2L F;Y2;X2;FF2R F;Y3;X2;F$2C F;W1 2 25 E'; my @seq2 = 'ID;P C;Y1;X1;K"Row 1" C;Y2;X1;K"Row 2" C;Y3;X1;K"Total" C;Y1;X2;K11 C;Y2;X2;K22 C;Y3;X2;K0;ER1C2+R2C2 E'; my $diff = diff \@seq1, \@seq2, {STYLE => "OldStyle"}; print $diff, "\n";